How do I get the .getJSON() jquery data out of the response?
function saveCallerReference(callerReference){
$.getJSON('/index.php?r=site/AJAXsaveCall开发者_JS百科erReference', function(data) {
console.log(data);
return data;
});
}
Given the above, the line "return data;" never gets returned, when the function(data){} exits, where does that return go? I want my outer scope function, saveCallerReference, to return the value from the getJSON(). console.log() is printing correctly so I am getting the data.
Where do you expect it to be returned to? the function being called is anonymous...
You need to understand that $.getJSON
happens asyncronously so the normal top-down flow does not apply, you need to do whatever you need to trigger whatever you want to do with data
inside the callback...
$.getJSON('/index.php?r=site/AJAXsaveCallerReference', function(data) {
functionThatDoesWhatYouWant(data);
});
精彩评论