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

A

Alex Li

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.
 
S

Steve van Dongen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top