Asynchronous JavaScript
I am building a Web App which relies heavily on asynchronous
javascript (XMLHttpRequest ).
It works a beautifully in IE7 and FF 2+ , but in IE6 (6.0.2900.2180
((sp2)) even though the asynchronous flag is set to true the call is
synchronous and doesn’t fork!! This problem is sporadic, only
happening on some peoples PCs some of the time and not others (with
the same full version as seen in Help->About). My code to test and
demonstrate this is as follows:.
The variables onExitRoot and callerHasLeft are used to test if the
Http Request was processed asynchronously. .
Any ideas why this doesn’t work on some versions of IE6…
try
{
var onExitRoot = false;
var callerHasLeft = false;
var req = CTalk.getHTTPRe q(); //get XMLHttpRequest or throw exception
if not supported
var reqStage1OK = false;
var to = setTimeout(func tion() { req.abort(); if(reqStage1OK)
CTalk.displayEr rOnCon(CTalk._M _ERRCON_TYPE_IN COMPLETE); else
CUi.displayMsg( "Error Connecting to X!",true); },
CTalk.respWaitA STol);
var url = "req.php?CI D=" + escape(CTalk._M _CLIENT_ID) + "&M=" +
escape(mtype + param);
CUtil.log("open ing ASync req: " + url);
req.open("GET", url, true);
req.onreadystat echange = function()
{
try
{
if(req)
{
CUtil.log("send AsyncReq state : " + req.readyState) ;
if(req.readySta te==1)
reqStage1OK = true;
else if(req.readySta te==4)
{
if(req.status== 200)
{
clearTimeout(to );
CUtil.log("HTTP 200 from sendAsyncReq, done.");
callback(req.re sponseText);
onExitRoot=true ;
}
else
{
clearTimeout(to );
CUtil.log("HTTP/1.1 ERR from sendAsyncReq.") ;
try { CUi.displayMsg( "Error",tru e); req.abort(); } catch(err) {}
onExitRoot=true ;
}
}
}
} catch(e) { CUtil.log(e.mes sage); alert("ERR: " + e.message); }
}
CUtil.log("Abou t to send data request");
req.send(null);
if(onExitRoot && !callerHasLeft)
{
CUtil.log("Asyn c not working!!");
//IF we get here async didn't work!!
//THis case is hit in IE6 on one call and then on a
subsiquent call it is not hit.
}
callerHasLeft = true;
} catch(e) { CUtil.log(e.mes sage); alert("ERROR: " + e.message); }
I am building a Web App which relies heavily on asynchronous
javascript (XMLHttpRequest ).
It works a beautifully in IE7 and FF 2+ , but in IE6 (6.0.2900.2180
((sp2)) even though the asynchronous flag is set to true the call is
synchronous and doesn’t fork!! This problem is sporadic, only
happening on some peoples PCs some of the time and not others (with
the same full version as seen in Help->About). My code to test and
demonstrate this is as follows:.
The variables onExitRoot and callerHasLeft are used to test if the
Http Request was processed asynchronously. .
Any ideas why this doesn’t work on some versions of IE6…
try
{
var onExitRoot = false;
var callerHasLeft = false;
var req = CTalk.getHTTPRe q(); //get XMLHttpRequest or throw exception
if not supported
var reqStage1OK = false;
var to = setTimeout(func tion() { req.abort(); if(reqStage1OK)
CTalk.displayEr rOnCon(CTalk._M _ERRCON_TYPE_IN COMPLETE); else
CUi.displayMsg( "Error Connecting to X!",true); },
CTalk.respWaitA STol);
var url = "req.php?CI D=" + escape(CTalk._M _CLIENT_ID) + "&M=" +
escape(mtype + param);
CUtil.log("open ing ASync req: " + url);
req.open("GET", url, true);
req.onreadystat echange = function()
{
try
{
if(req)
{
CUtil.log("send AsyncReq state : " + req.readyState) ;
if(req.readySta te==1)
reqStage1OK = true;
else if(req.readySta te==4)
{
if(req.status== 200)
{
clearTimeout(to );
CUtil.log("HTTP 200 from sendAsyncReq, done.");
callback(req.re sponseText);
onExitRoot=true ;
}
else
{
clearTimeout(to );
CUtil.log("HTTP/1.1 ERR from sendAsyncReq.") ;
try { CUi.displayMsg( "Error",tru e); req.abort(); } catch(err) {}
onExitRoot=true ;
}
}
}
} catch(e) { CUtil.log(e.mes sage); alert("ERR: " + e.message); }
}
CUtil.log("Abou t to send data request");
req.send(null);
if(onExitRoot && !callerHasLeft)
{
CUtil.log("Asyn c not working!!");
//IF we get here async didn't work!!
//THis case is hit in IE6 on one call and then on a
subsiquent call it is not hit.
}
callerHasLeft = true;
} catch(e) { CUtil.log(e.mes sage); alert("ERROR: " + e.message); }
Comment