Synchronous JQuery.post() Synchronous JQuery.post() ajax ajax

Synchronous JQuery.post()


You need to force your ajax call to be synchronous my friend ;)

http://api.jquery.com/jQuery.ajax/

ex:

asyncBooleanDefault: true

By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.


I actually found that adding this snippet worked so I didn't have to change my .post() to .ajax()

$.ajaxSetup({ async: false });

I'm not sure if it will also change the settings of my other ajax calls though


If you use async: false you should be able to put each of your ajax calls into a queue until they get to be executed in a synchronous method. Like so:

 for( var i=0;i < x;i++ ){     $.ajax({url: 'myurl',             async: false,             success: function(data){                        //do something with the returned 'data'                      };    }); }