Is it possible to set async:false to $.getJSON call
You need to make the call using $.ajax()
to it synchronously, like this:
$.ajax({
url: myUrl,
dataType: 'json',
async: false,
data: myData,
success: function(data) {
//stuff
//...
}
});
This would match currently using $.getJSON()
like this:
$.getJSON(myUrl, myData, function(data) {
//stuff
//...
});
Both answers are wrong. You can. You need to call
$.ajaxSetup({
async: false
});
before your json ajax call. And you can set it to true after call retuns ( if there are other usages of ajax on page if you want them async )
I think you both are right. The later answer works fine but its like setting a global option so you have to do the following:
$.ajaxSetup({
async: false
});
//ajax call here
$.ajaxSetup({
async: true
});