Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set async:false to $.getJSON call

Is it possible to set async: false when calling $.getJSON() so that the call blocks rather than being asynchronous?

like image 568
ACP Avatar asked May 04 '10 12:05

ACP


People also ask

What does async false do in Ajax call?

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.

Is async false deprecated?

As of jQuery 1.8, the use of async:false in jQuery. ajax() is deprecated.

What is async true in Ajax call?

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.

How do I stop async false in Ajax?

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'.


1 Answers

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   //... }); 
like image 118
Nick Craver Avatar answered Sep 18 '22 19:09

Nick Craver