Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   Re-using XMLHttpRequest object (IE) (http://www.programmingforums.org/showthread.php?t=13255)

bewareofcabbage May 31st, 2007 7:35 AM

Re-using XMLHttpRequest object (IE)
 
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;
}



All times are GMT -5. The time now is 2:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC