I have something like this:
var someJSON = function(){
// Calculate some stuff here
$.ajax({
dataType: "json",
url: "http://somewebsite.com/api/?callback=?",
async: false,
success: function(data) {
return data; // How can I return this so that someJSON gets this value?
}
});
}();
console.log(someJSON); // I want someJSON to be = data from the ajax call
Essentially, I want someJSON
to end up being the value of this json data that is returned via ajax. How do I return the value from the nested $.ajax
call though? Can I use some sort of callback that the value gets passed back through?
Also I'm using async: false
with this so that the rest of the script doesn't try to execute until someJSON
has a value set. Is that the right way to do this?