I have code that looks like this:
jQuery.getJSON( "url/to/some/script.php", function( data ) {
var test = data.someValue;
console.log('This message should occur first');
});
console.log('this message should occur second');
// do things with data retrived above...
What's happening is, that first console.log is executing AFTER the second one. I suppose because it's taking time to make the Ajax request, but I didn't realize it would continue moving down the script without finishing. As such, variables that result from the AJAX request are 'undefined' when I try and use them in the code directly following this.
What might be the best way to deal with such a situation?