edg322 Posted June 20, 2007 Share Posted June 20, 2007 My problem has to do with AJAX/js and innerHTML in IE. I have a very basic AJAX script that calls a file which should display fresh content every few seconds. All this is within div tags on my main page. It works fine in FF of course. It also works in IE if you have Tools-> Internet options -> Settings "Check for newer versions of stored pages" set to "Every visit". If you change that to "Automatically" then it breaks. Actually if you change it to anything other than the "Every visit" it doesn't work. Apparently Microsoft caches in the temp files every GET request. Well guess what, I change the AJAX call to POST and it's the same problem. So the POST option is out. I also can't ask users to change their browser settings. I also can't change my meta tags, which I believe has an option somewhere to force a new page. So I'm wondering if there is a way in javascript to force new contents on every page refresh. Anyone know a way to do it like that? Quote Link to comment Share on other sites More sharing options...
edg322 Posted June 20, 2007 Author Share Posted June 20, 2007 Here's the code: Code: function GetXmlHttpObject() { var xmlHttp=null; try {xmlHttp=new XMLHttpRequest();} catch(e) { try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} catch(e) {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} } return xmlHttp; } function getPage(thePageToGet) { xmlHttp=GetXmlHttpObject(); if(xmlHttp==null) {alert("Your browser doesn't support AJAX!");return;} var url = thePageToGet; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if(xmlHttp.readyState==4) { if (xmlHttp.responseText) { document.getElementById("featured_area").innerHTML=xmlHttp.responseText; t=setTimeout('getPage("get_images.cfm")',5000); } } } like I said, very basic script. There's a span tag on my page called "featured_area" and that content should be refreshed from the contents of 'thePageToGet' which is just dynamically grabbing some images and the urls they link to: Code: <span id="featured_area"> <script> getPage("get_images.cfm") </script> </span> Quote Link to comment Share on other sites More sharing options...
edg322 Posted June 20, 2007 Author Share Posted June 20, 2007 ok I got a solution worked out. If you add the current time at the end of the URL string being called, that will force IE to get the fresh page (instead of grabbing cached content) Change the getPage function to getPage("get_images.cfm?ts=") And add into the js: var now = new Date(); var url = thePageToGet + now.getTime(); This way instead of IE looking to refresh just "get_images.cfm" it's now looking to refresh "get_images.cfm?ts=1182352248509" which will of course change every time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.