Esha Ch Esha Ch - 1 year ago 52
Ajax Question

Calling a function is JQuery after all ajax calls(number of ajax calls are dynamic) have received responses




$("#result").html("function started here");
var requests = Array();
requests.push($.get(', Bangalore'));
var defer = $.when.apply($, requests);
    // This is executed only after every ajax request has been completed
    $.each(arguments, function(index, responseData){

// alert(index);
        // "responseData" will contain an array of response information for each specific request


The above snippet works only when all ajax calls returns "success" response. Is there any way where i can know if all ajax calls gets response,may it be "success" / "failure" .

Answer Source

you can you ajaxStart,ajaxStop,ajaxError,ajaxSuccess.

 $(document).ajaxStart(function () {
            //when ajax start
        }).ajaxStop(function () {
           //when ajax stop
        }).ajaxError(function () {
            //when ajax error
        }).ajaxSuccess(function () {
        // when ajax success

This will trigger for every ajax call.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download