Feb
05
jQuery getJSON() async false
Today I searched jQuery getJSON() async false because I needed my jQuery Ajax call to be synchronous. It turns out that getJSON is just an Ajax shortcut in jQuery that can not have any extra parameters passed to it according to a post at Stackoverflow.com and then confirmed in the jQuery doc . So I had to turn my call back to normal jQuery.ajax().
//before
$.getJSON(url, data, function(json){
//success code
});
//after
$.ajax({
url: url,
dataType: 'json',
data: data,
async: false,
success: function(json){
//success code
}
});
As you can see the shortcut code is well, shorter, but not as flexible as the basic ajax function. Shortcuts are nice but shouldn’t be leaned on for heavy lifting.

This is exactly, what I needed. Thanks!
“As you can see the shortcut code is well, shorter, but not as flexible as the basic ajax function. Shortcuts are nice but shouldn’t be leaned on for heavy lifting.”
So true!
Thanks for this, I was also after a synchronous getJSON(). Your solution (as expected due to getJSON docs) works a treat.
Won’t this work?
http://api.jquery.com/jQuery.ajaxSetup
Yes that will work if you want all of your future calls to be synchronous. Most of the time you only want a certain call to be synchronous in which this solution is better for.