[Solved] how to make multiple ajax calls from a same function? [closed]


var pages = ["page1.php","page2.php","folder/page3.php"]
var requests = [];

function multipleAjax(string) {
    /*where string is "?value=somevalue&bool=true" or something*/

    for (i=0; i<pages.length;i++) {
        requests[i] = getXMLHttpRequest();

        if (requests[i] != null) {
            requests[i].open("Post", "https://stackoverflow.com/" + pages[i] + string);

            requests[i].onreadystatechange = function () {
                if (requests[i].readyState == 4) {
                    /*code to handle responseText returned*/
                };
            };

        };

        requests[i].send();
    };
};

function getXMLHttpRequest() {
    var re = "nothing";
    try {re = new window.XMLHttpRequest();} catch(e1) {};
    try {re = new ActiveXObject("MSXML2.XMLHTTP.4.0");} catch(e) {};
    try {re = new ActiveXObject("Msxml2.XMLHTTP");} catch(e2) {};
    try {re = new ActiveXObject("Microsoft.XMLHTTP");} catch(e3) {};
    try {re = new ActiveXObject("MSXML2.XMLHTTP.3.0");} catch(ex) {};
    if (re != "nothing") {return re;}
    else {return null;};
};

0

solved how to make multiple ajax calls from a same function? [closed]