1

I can get response when 'all' Ajax requests are done from this question.

Wait until all jQuery Ajax requests are done?

While I can't find a question to get 'every' response when each Ajax are done.

How can I do this?

Example for wait until all responses done, but I want to get response when each ajax complete.

function translate(...){
    return $.ajax({
        // settings...
    });
});

var requests = [];
translatable_fields.each(function(){
    requests.push(translate(...));
});

$.when.apply($, requests).done(function(schemas) {
     console.log("All requests complete");
    // do something...
});
Community
  • 1
  • 1
Leo Hsieh
  • 351
  • 4
  • 12

1 Answers1

0

The responses will be passed to the callback for done. Each AJAX call will get its own parameter, and each parameter will be an array of the three parts of the response: the response text, the status, and the jqXHR object associated with the AJAX call. Documentation for $.when

You can get the response texts all at once using the arguments object:

$.when.apply($, requests).done(function() {
    var responses = $.map(arguments, function(arr) { return arr[0] });
});
4castle
  • 32,613
  • 11
  • 69
  • 106