JSFiddle - React, Tailwind, and code Playground
HTML
<div id='console'></div>
JavaScript
function log(msg) {
var $out=$("<div />");
$out.html(msg);
$("#console").append($out);
}
function fireRequest(country) {
return $.ajax({
type: "GET",
url: "/echo/json/",
data: {country:country},
dataType: "JSON",
success: function(){
log("Successful request for [" + country + "]");
}
});
}
var countries=["US","CA","MX"], startingpoint=$.Deferred();
startingpoint.resolve();
$.each(countries,function(ix,country) {
startingpoint=startingpoint.pipe( function() {
log("Making request for [" + country + "]");
return fireRequest(country);
});
});