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

actually i 'm calling multiple ajax calls but i want some ajax calls completes first and exectute the atsk defined in its stop function.but some ajax call should be made once function defined in stop method executes and those ajax call should not cal.stop method once 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 here but should not call .ajaxstop this time

i'm putting my question in this way:

suppose there are two ajax call to webservice. when one ajax call completes the function dependent on taht ajax call should get executed before waiting for second jax call execution.for eaxample: one ajax call create chart and other ajax call log user activities.if a functon to display chaet is dependent on create chart so that function get executed before calling aax call for log activities.no waiting for ajajx call for user activities

Answers


I think you want to set:

 async: false

By default, all requests are sent asynchronously . If you need synchronous requests, set this option to false. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. See also this old question. How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?


As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the complete/success/error 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 with async: false if its something the platform allows - why restrict it? I'd just set a timeout to minimize the impact of a hang.

Nonetheless, I'm using a queue now in 1.8, which is non-blocking, and works quite nicely. Sebastien Roch created a easy to use utility that allows you to queue up functions and run/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 2 functions I pass the queue object into the calls, here's what the calls would look like:

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

// similar for ajaxCall2

Notice the queue.pause(); at the beginning of each function, and queue.run() to continue queue execution at the end of your complete statement.


Need Your Help

How can I find the nearest intersection via the Google Maps API?

javascript api google-maps geocoding

How can I find the closest intersection of the street I have coordinates of?

Will dynamic content pulled from a database be indexed by search engines?

ms-access indexing search-engine

I have blog posts stored in an Access database. They are displayed dynamically when ASP pages are loaded. Therefore, there are no publicly accessible files containing the bodies of blog posts excep...