我需要刷新页面的一部分,然后使用这个在FF和Chrome中运行的脚本, 但这在IE中不起作用。
<script language="JavaScript">
<!--
var page = "ASP/include/ithome.asp";
var MyDelay = function () { ajax(page, 'scriptoutput'); };
function ajax(url,target)
{
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'sending...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send();
}
}
setTimeout(MyDelay, 12000);
}
function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}
}
}
function winOp(link, width, height) {
window.open(link, '', 'toolbar="no",scrollbars=no,resizeable="no",height=' + height + ',width=' + width + '');
}
// -->
</script>
<body background="images/Pattern.gif" onload="ajax(page,'scriptoutput')">
...
我想,问题出现在setTimeout中,但是当我对该页面进行调试时,它看起来很有效。 也许req.open(“GET”,url,true)从缓存中打开了ASP页面。你能帮帮我吗?
谢谢
L,
答案 0 :(得分:0)
当你说:
时,你是对的也许
req.open("GET", url, true)
从缓存中打开了ASP页面
IE将通过GET
请求缓存Ajax响应。只需执行此类操作(这将使所有请求都具有唯一的查询字符串,因此缓存不会成为问题):
req.open("GET", [url, "&_=", new Date().getTime()].join(""), true);