JSFiddle - React, Tailwind, and code Playground

by sandhyasriraj

HTML

<div id='console'></div>

JavaScript

var x = null;
var i = 0;
x= $.Deferred();
var countries=["US","CA","MX","bx","fs","ZX"];
function log(msg) {
    var $out=$("<div />");
    $out.html(msg);
    $("#console").append($out);
}


callX = function(j) {
    return $.ajax({
            type: "GET",
            url: "/echo/json/",
            data: {country:countries[i]},
            dataType: "JSON",
            success: function(){
                log("Successful request for [" + countries[j] + "]");
                i++;      
                x.resolve();
                xy();
               }
        });

}
x.resolve();
xy = function()
{
    debugger;
    if(i > 5)
        return;
    
     $.when(x).then(function() {
        x = $.Deferred();
        log("Making request for [" + countries[i] + "]");
        callX(i);
    });
}
xy();