================================================== ==
Expand|Select|Wrap|Line Numbers
- function getXMLHTTPRequest()
- {
- try
- {
- req = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch (err) { }
- return req;
- }
- // update the window status
- function updateStatus()
- {
- window.status += '-';
- }
- var httpReq = null;
- function loadURL(dest, trigfunc)
- {
- // create only when needed
- if (httpReq == null) { alert("Create httpReq"); httpReq = getXMLHTTPRequest(); }
- while (1)
- {
- // only sumbit another Ajax calls when the readsyState is 0
- if (httpReq.readyState == 0)
- {
- httpReq.onreadystatechange = trigfunc;
- httpReq.open("GET", dest, true);
- httpReq.send(null);
- break;
- }
- // delay the while loop execution for 500 milisec by updating the status line
- else window.setTimeout("updateStatus()", 500);
- }
- }
- // Ajax triggered function processes different business logic depending on the
- // content of responseText
- function trigFunc()
- {
- if (httpReq.readyState == 4)
- {
- // Process the responseText from httpReq
- ..................
- // to reset the httpReq.readyState to 0 so next Ajax calls can be submitted
- httpReq.abort();
- }
- }
- function myFunc()
- {
- // Test for some condition on the web page
- if (condition is true)
- loadURL(urlOne, trigFunc);
- loadURL(urlTwo, trigFunc);
- }
I thought after the loadURL(urlOne, trigFunc) call made, loadURL(urlTwo, trigFunc) call will be made but never submitted until the triggered function from the first call executed and reset the readyState to 0.
While the first call is executed on the server side, window will stay in the loop and update the status.
IT NEVER WORKED. For some reason, the result of second call is lost and window stuck in the forever loop.
Can anyone offer some hint to my problem ? Thanks