How to make other ajax calls after completing one ajax call and the second ajax call should not call the .stop function

I actually make several ajax calls, but I want some ajax calls to complete first and set the atsk defined in its stop.but function, and some ajax call should be executed after the function defined in the stop method is executed, and these ajax calls shouldn't .stop again

$('.badgeContainer').ajaxStop(function() { alert("ajax rqst completed"); }); $.ajax({ type: "POST", url: "WebServices/abc.asmx/dosomething", data: "{ }", contentType: "application/json; charset=utf-8", dataType: "json", success: function(serviceReply) { var serviceReplyArray = serviceReply.d.split("#"); }, error: function(xhr, errDesc, exception) { } }); 

another ajax call is here, but this time should not be called .ajaxstop

I ask my question this way:

Suppose there are two ajax calls for a webservice. when one ajax call completes a taht-dependent function, the ajax call must be executed before waiting for the second jax call to complete. For eaxample: one ajax call creates a diagram and other user actions in the ajax call log. If the functionality for displaying chaet depends on the creation diagram, so the function will be executed before the aax-call for the log actions is called. Without waiting for ajaj call for user actions

+4
source share
2 answers

I think you want to install:

  async: false 

By default, all requests are sent asynchronously. If you need synchronous requests, set this parameter to false. Please note that synchronous requests can temporarily block the browser, disabling any actions while the request is active.
See Also this old question.
How can I get jQuery to execute a synchronous rather than asynchronous Ajax request?

+4
source

As in jQuery 1.8, using async: false with jqXHR ($ .Deferred) is deprecated; you must use full / successful / callbacks.

http://api.jquery.com/jQuery.ajax/ (async section)

I found this a bit annoying ... developers should be given the choice to make a blocking call using async: false , if this is what the platform allows - why limit it? I just set a timeout to minimize the impact of freezes.

However, I use the queue in 1.8, which does not block and works pretty well. Sebastien Roch has created an easy-to-use utility that allows you to queue functions and start / pause them. https://github.com/sebastien-roch/Jquery-Async-queue

  queue = new $.AsyncQueue(); queue.add(function (queue) { ajaxCall1(queue); }); queue.add(function (queue) { ajaxCall2(queue); }); queue.add(function() { ajaxCall3() }); queue.run(); 

In the first two functions, I pass the queue object to the calls, this is what the calls look like:

 function ajaxCall1(queue) { queue.pause(); $.ajax({ // your parameters .... complete: function() { // your completing steps queue.run(); } }); } // similar for ajaxCall2 

Pay attention to queue.pause(); at the beginning of each function and queue.run() to continue executing the queue at the end of your complete statement.

0
source

All Articles