10.22.2017

How to save .getJSON result into global variable?

How to return a variable from a $.getJSON function?
How to save .getJSON result into global variable
You can't get value when calling getJSON because getJSON is an async call. Any code that you want to execute with the results of the getJSON call needs to happen either within that callback function or after the callback executes.
$.getJSON(url, data, callback(result) {
// Do something with result here
});
or
$.getJSON(url, data, callback(result)});
function callback (result){ // Do something with result here }

No comments:

Post a Comment