how do i make data overwrite results variable ?
var ajax = {
get : {
venues : function(search){
var results = "@";
$.getJSON("http://x.com/some.php?term="+search+"&callback=?",function(data){ results = data; });
return results;
}
}
};
datais overwritingresults, just afterresultshas been returned.You can use the
ajaxfunction instead ofgetJSON, sincegetJSONis just shorthand forand then also set
asynctofalse, so that the call will block.However, in your case this won’t work, because JSONP requests (with
"?callback=?") cannot be synchronous.The other (better) option is to have whatever code is dependent on the
resultsreturn value get called by thesuccesscallback.So, instead of something like this:
Maybe something like this: