Is it possible to set async: false
when calling $.getJSON()
so that the call blocks rather than being asynchronous?
jQuery Ajax Async False is a function of jQuery in which if we set async as false that means the first statement has to be complete before calling the next statement. If we set the async request as true, then the next statement will begin its execution whether the previous statement is completed or not.
As of jQuery 1.8, the use of async:false in jQuery. ajax() is deprecated.
by default async is true. it means process will be continuing in jQuery ajax without wait of request. Async false means it will not go to next step untill the response will come. By default async is true process will be continuing in jQuery ajax without wait of request.
Don't just use callback functions as you might read on the web or in other answers. Learn about Deferred and Promise objects, and instead of returning the data, return a promise that you can use to attach behavior to when that promise is 'resolved'.
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 //... });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With