MSXML2.XMLHTTP Caching?
I've been trying to use MSXML2.XMLHTTP to refresh content on a page without reloading the entire page. Any idea why the request I make is permanently cached? The program works and gets the new data from an HTML file, but it always stays the same even after I run a refresh. The only way to clear it is to shut down the Web browser and load it again. It looks like MSXML2.XMLHTTP is caching the request permanently in teh browser session. This will not work for me because the content in the HTML page changes.
Please help. The illustration below SHOULD refresh the DIV every 3 seconds. The LoadNew() function does definitely run every 3 seconds (I tested it by putting an alert in there). The problem is that xmlhttp.open("get",filename,false) is cached and always returns the exact same data. I can even delete the myfile.cfm file and it will still return the cached content instead of a 404. Any way to prevent this caching effect?????
Illustration:
<html>
<head>
<title>DIV should change without reloading page.</title>
<script type="text/javascript">
<!--
var xmlhttp = false
// Creating XMLHTTP Start
try {
xmlhttp=new ActiveXObject("MSXML2.XMLHTTP")
} catch (e) {
}
if (!xmlhttp) {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
}
}
// Creating XMLHTTP End
function LoadNew() {
if (!xmlhttp) {alert("Your browser doesn't support XMLHTTP.\nYou need IE5+ or NN 6.1+");return}
var filename = "/myfile.asp";
xmlhttp.open("GET",filename,false);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var html = xmlhttp.ResponseText;
if (xmlhttp.status==404) {alert("The page doesn't exist on the server !!!");return}
document.getElementById("dynamic").innerHTML = html;
}
}
// xmlhttp.open("DELETE",filename,true);
xmlhttp.send();
// xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
// xmlhttp.close;
setTimeout("LoadNew()",3000);
}
// -->
</script>
</head>
<body>
<p>This channel should reload every 3 seconds. <a href="javascript:LoadNew();">Force reload now</a></p>
<div id="dynamic">
Dynamic part
</div>
<script type="text/javascript">
setTimeout("LoadNew()",3000);
</script>
</body>
</html>
|