Jump to content

Help Needed For AJAX Script


NoSalt

Recommended Posts

Hello All

 

    I am working on an AJAX script but am having difficulties. First, here is the script:

 

var xmlHttp;

function GetXmlHttpObject(){
    var objXMLHttp=null
    if (window.XMLHttpRequest){
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject){
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function retrieveData(){
    var jBossServer = new Array();
    jBossServer[0] = "d01";
    jBossServer[1] = "d02";
    jBossServer[2] = "p01";
    jBossServer[3] = "p02";

    for(var i=0; i<jBossServer.length; i++){
        xmlHttp = GetXmlHttpObject();

        if (xmlHttp == null){
            alert ("Something weird happened ...");
            return;
        }

        var url="./retrieveData.php";
        url = url + "?jBossID=" + jBossServer[i];
        url = url + "&sid=" + Math.random();
        xmlHttp.open("GET",url,true);
        xmlHttp.onreadystatechange = updateMemory;
        xmlHttp.send(null);
    }
}

function updateMemory(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
        aggregateArray = new Array();
        aggregateArray = xmlHttp.responseText.split(',');

        for(var i=0; i<aggregateArray.length; i++){
            alert(aggregateArray[i]);
        }

        return;
    }
}

 

The "retrieveData.php" page will return data that looks like this:

 

d01,1 MB,2 MB,3 MB

 

They relate to my 4 servers d01, d02, p01, and p02 (dev and prod).

 

I want to save code so I attempted to put the AJAX xmlHttp call into a loop, but I don't think it is working. All I ever get back is the information for "p02" four times. Am I able to do what I want or do I need four different functions for each server (i.e., xmlHttpServer01, xmlHttpServer02, xmlHttpServer03, xmlHttpServer04)?

 

Thank you all for reading, have a good day.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.