JSFiddle - React, Tailwind, and code Playground
JavaScript
var AJAX_CALLS = [
{ response: 'response0', delay: 1.0 },
{ response: 'response1', delay: 0.2 },
{ response: 'response2', delay: 0.5 },
];
var requests = $.map(AJAX_CALLS, function(ajaxCall) {
return $.ajax('/echo/html/', {
type: 'post',
data: {
html: ajaxCall.response,
delay: ajaxCall.delay
},
dataType: 'text'
});
});
$.when.apply($, requests).done(function() {
var results = (requests.length > 1)
? $.map(arguments, function(a) { return a[0]; })
: [arguments[0]];
console.log(results);
});