Making local variable global
Hello,
I have this code:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
//var myd=""; // I want this to contain the contents of data
$("button").click(function(){
$.get("pictures.json",function(data,status){
console.log( data ); // This does contain data
});
});
// console.log( myd ); // This results in error but I want myd to contain data from the $.get
});
</script>
</head>
<body>
<button>Send an HTTP GET request to a page and get the result back</button>
</body>
</html>
What I want to do is make data a global variable after the $.get function retrieves it. This is not so much on how $.get works but rather how to make data available outside of $.get function. Any ideas?
Thanks,
Jim