getJSON Synchronous
Since $.getJSON() uses ajax configurations, just set the global ajax configs:
// Set the global configs to synchronous $.ajaxSetup({ async: false});// Your $.getJSON() request is now synchronous...// Set the global configs back to asynchronous $.ajaxSetup({ async: true});
Asynchronusly does mean the Request is running in the background, and calls your function back when it got a response. This method is best if you want to have a result but allow to use your app within the request. If you want to have a direct response, take a look at a synchron request. this request will pause script execution until it got a response, and the user can not do anything until the response was recieved. You can toggle it via:
async: false,
So for example:
$.ajax({ url: "myurl", async: false, ...})
$.getJSON(), doesn't accept a configuration, as it says in the docs it's a shorthand version of:
$.ajax({ dataType: "json", url: url, data: data, success: success});
So just rewrite your request in terms of that and async:false will work just as you expect.