Hi guys, I've been tearing my hair out over this. Firefox accepts the following code perfectly, and executes the onreadystatechange function every time. However IE7 (I'm going to try IE6 at work tomorrow) will only execute the function once, any further AJAX requests stick on my "loading..." message, unless you refresh the page and start all over again.
I found articles about problems re-using the XMLHttpRequest object in IE, and they said to shift the onreadystatechange (in the "ajaxGet" function) below the open line (see
http://keelypavan.blogspot.com/2006/...ect-in-ie.html ). But this isn't working for me, here's my javascript - any ideas greatly appreciated!
var xmlHttp;
function createXMLHttpRequest()
{
if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
return xmlHttp;
}
else if (window.ActiveXObject)
{
xmlHttp = ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
}
function handleStateChange(divID)
{
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
document.getElementById(divID).innerHTML = xmlHttp.responseText;
}
}
}
function ajaxGet(divID, URL, loadmsg)
{
createXMLHttpRequest();
xmlHttp.open("GET", URL, true);
xmlHttp.onreadystatechange = function() { handleStateChange(divID); } ;
xmlHttp.send(null);
if(loadmsg != "") { document.getElementById(divID).innerHTML = '<div style="color:#A9A9A9; padding:5px;"><img src="_img/parts/progress_ball.gif" style="vertical-align:text-bottom;"> ' + loadmsg + "</div>"; }
return false;
}