AJAX 1 by 1

Solution by Azeem for Stackoverflow

by mFiddler

HTML

<button id="btnAJAX">AJAX one by one</button>

JavaScript

$(document).ready(function () {

    urlsArray = ['/echo/html/', '/echo/html/', '/echo/html/'];

    $("#btnAJAX").click(

    function () {
        arrayIndex = 0;
        doAjax(arrayIndex);
    });
});

function doAjax(arrayIndex) {
    var urlCount = arrayIndex + 1;
    var theURL = urlsArray[arrayIndex];
    alert(urlCount + ", Start AJAXing the url: " + theURL);
    $.ajax({
        type: 'GET',
        url: theURL,
        dataType: 'json',
        success: function (data) {
            alert(urlCount + ", Done AJAXing the url: " + theURL);
            if (arrayIndex < urlsArray.length - 1) {
                arrayIndex += 1;
                doAjax(arrayIndex);
            }
        }
    });
}