Jump to content

Need to click the browser reload to get correct result from Ajax


stockton

Recommended Posts

The following code returns the correct results from the server but the web page at the client does not display the correct information until the browser(IE6) reload button is clicked.

Please tell me how I fix this.

As you can see I have tried history.go(0); as well all without success.

 

function getXMLHttpRequest ()
    {
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
    try { return new XMLHttpRequest(); } catch(e) {};
    return null;
    }

// Make the XMLHttpRequest object
    var xhr = getXMLHttpRequest();

function progExe(CommandString)
    {
//    alert("Mandy");
    xhr.open("GET", CommandString, true);
    xhr.onreadystatechange = ServerResponse;
    xhr.send(null);
    }

function ServerResponse()
    {
//    alert("entered ServerResponse()");
/* The full list of the readyState values is as follows:
    * 0 (uninitialized)
    * 1 (loading)
    * 2 (loaded)
    * 3 (interactive)
    * 4 (complete)
*/
    if(xhr.readyState == 0)
        {
        document.getElementById("loadingNode").innerHTML = "Uninitialized........";
        }
    else
    if(xhr.readyState == 1)
        {
        document.getElementById("loadingNode").innerHTML = "Loading........";
        }
    else
    if(xhr.readyState == 2)
        {
        document.getElementById("loadingNode").innerHTML = "Loaded........";
        }
    else
    if(xhr.readyState == 3)
        {
        document.getElementById("loadingNode").innerHTML = "Interactive........";
        }
    else
    if(xhr.readyState == 4)
        {
        if (xhr.status == 200)
            {
            var parts = xhr.responseText.split("|");
//           alert("0 = "+parts[0]+" 1 = "+parts[1]);

            if (parts[0] == "X")
                {
                alert(parts[1]);
                }
            else
                {
                document.getElementById("loadingNode").innerHTML = " ";
                document.getElementById("DIssued").innerHTML = parts[1];
                document.getElementById("DSuggestion").innerHTML = parts[2];
                document.getElementById("CIssued").innerHTML = parts[3];
                document.getElementById("CSuggestion").innerHTML = parts[4];
                document.getElementById("LIssued").innerHTML = parts[5];
                document.getElementById("LSuggestion").innerHTML = parts[6];
                document.getElementById("XIssued").innerHTML = parts[7];
                document.getElementById("XSuggestion").innerHTML = parts[8];
                document.getElementById("IIssued").innerHTML = parts[9];
                document.getElementById("ISuggestion").innerHTML = parts[10];
                document.getElementById("BundleNum").value = "";
                var SlotsValue = (parts[11])*1;
                var TableValue = (parts[12])*1;
                var BonusTickets = (parts[13])*1;
                var SlotsIssued = (parts[14])*1;
                var TableIssued = (parts[15])*1;
                var BonusIssued = (parts[16])*1;
        // alert("SlotsValue = "+SlotsValue+" TableValue = "+TableValue+" BonusTickets = "+BonusTickets+"\nTotal Issued = "+TotalIssued+" Remaining Tickets = "+RemainingTickets);
        // Calculate Remaining tickets
                var RemainingTickets = ((SlotsValue*1 + TableValue*1 + BonusTickets*1) - (SlotsIssued*1 + TableIssued*1 + BonusIssued*1));
                document.getElementById("TablesValue").innerHTML = RemainingTickets;
        // Calculate Total Issued
                var TotalIssued = SlotsIssued*1 + TableIssued*1 + BonusIssued*1;
                document.getElementById("Total").innerHTML = TotalIssued;
                document.getElementById("ErrorMessage").innerHTML = parts[17];;
//              history.go(0);
                }
            }
        }
    }

Link to comment
Share on other sites

Rajiv, appreciate your answer but do not understand it.

What URL are you speaking of? Ajax does not call a URL as the effected page is already displayed.

As the page were the data is to be displayed is already on the client machine how does the web server get involved?

As far as I understand how Ajax works is that an HTML(on click or whatever) calls Ajax which in turn calls an application on the server which returns data to Ajax which then displays that data on an existing page.

What am I misunderstanding? 

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.