problem to display a "wait" message before fetching data using MS's XMLHTTP

Discussion in 'Javascript' started by Alex Li, Feb 12, 2004.

  1. Alex Li

    Alex Li Guest

    Dear js/xmlhttp experts,

    I spent hours but could not solve this problem and hope someone could
    give me a clue: a onclick event will invoke a function to do a few
    things:
    1. make a hidden DIV "wait" message visible by changing its
    style.display to "block"
    2. download the data with XMLHTTP
    3. make the hidden DIV message invisible by setting its display to
    "none".

    If I insert "alert("test")" between 1 and 2, everything works fine.
    However, if I comment out "alert" statement, step 1 will happen after
    step 2, which totally defeats the purpose of "wait" message. The
    detailed (simplified) is below:

    function downloadData {
    // waitDiv below is a pre-defined global DIV object
    waitDiv.style.display = 'block'; // display "please wait ..."
    alert("test"); // without this, the above statement execution
    seems to be delayed.

    // cgiUrl and postData are global.
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    xmlhttp.Open("POST", cgiUrl, false);
    xmlhttp.Send(postData);
    //antherDiv below is also pre-defined global DIV object.
    anotherDiv.innerHTML = xmlhttp.responseText;

    waitDiv.style.display = 'none'; // now hide "please wait ..."
    }

    I would greatly appreciate any help!!!

    Alex.
     
    Alex Li, Feb 12, 2004
    #1
    1. Advertising

  2. (Alex Li) wrote:

    >Dear js/xmlhttp experts,
    >
    >I spent hours but could not solve this problem and hope someone could
    >give me a clue: a onclick event will invoke a function to do a few
    >things:
    >1. make a hidden DIV "wait" message visible by changing its
    >style.display to "block"
    >2. download the data with XMLHTTP
    >3. make the hidden DIV message invisible by setting its display to
    >"none".
    >
    >If I insert "alert("test")" between 1 and 2, everything works fine.
    >However, if I comment out "alert" statement, step 1 will happen after
    >step 2, which totally defeats the purpose of "wait" message. The
    >detailed (simplified) is below:
    >
    >function downloadData {
    > // waitDiv below is a pre-defined global DIV object
    > waitDiv.style.display = 'block'; // display "please wait ..."
    > alert("test"); // without this, the above statement execution
    >seems to be delayed.
    >
    > // cgiUrl and postData are global.
    > var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    > xmlhttp.Open("POST", cgiUrl, false);
    > xmlhttp.Send(postData);
    > //antherDiv below is also pre-defined global DIV object.
    > anotherDiv.innerHTML = xmlhttp.responseText;
    >
    > waitDiv.style.display = 'none'; // now hide "please wait ..."
    >}
    >
    >I would greatly appreciate any help!!!


    You have to send the request asyncronously. See
    http://jibbering.com/2002/4/httprequest.html for an example.

    Regards,
    Steve
     
    Steve van Dongen, Feb 12, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    15,560
    ishahdad
    Dec 31, 2007
  2. Bhavesh
    Replies:
    0
    Views:
    445
    Bhavesh
    Jul 16, 2007
  3. Bhavesh
    Replies:
    5
    Views:
    681
    Bhavesh
    Jul 18, 2007
  4. Bhavesh
    Replies:
    1
    Views:
    470
    Bhavesh
    Jul 17, 2007
  5. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    439
    Matt Kruse
    Nov 9, 2006
Loading...

Share This Page