Forum Moderators: open
I'm using AJAX ala google suggest to grab a page to keep the visitor updated as to the status of a request. The problem I ran into is that in IE the object was caching the page that it was calling instead of retrieving the updated page.
The fix I found was to add a request header If-Modified-Since to the request such that it would be before the page was modified.
Here's the code.
var _xmlHttp=null;//This will be the object to retrieve the page
function getXMLHTTP() {
var A=null;
try { A=new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e)
{
try
{ A=new ActiveXObject("Microsoft.XMLHTTP");}
catch(oc)
{ A=null; }
}
if(!A && typeof XMLHttpRequest!= "undefined") {
A=new XMLHttpRequest();
}
return A;
}//Sets the content of B
function SetDiv() {
if(_xmlHttp.readyState==4 && _xmlHttp.responseText) {
while(B.childNodes.length>0) {
B.removeChild(B.childNodes[0]);
}
B.innerHTML = _xmlHttp.responseText;
}
}//Requests whatever the page is and specifies where to put the contents
function getPage(the_page,the_div) {
B = document.getElementById(the_div);
_xmlHttp=null;
_xmlHttp=getXMLHTTP();
//I needed to keep track of the Cold Fusion session for which the page was being called
if(the_page.indexOf("?") >= 0) {
the_page = the_page + "&cfid="+getCookie('cfid')+"&cftoken="+getCookie('cftoken')
} else {
the_page = the_page + "?cfid="+getCookie('cfid')+"&cftoken="+getCookie('cftoken')
}
_xmlHttp.open("GET",the_page,true);
_xmlHttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
_xmlHttp.onreadystatechange = SetDiv;
_xmlHttp.send(null);
}