我需要刷新我页面的一部分,我使用这个在 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.
最佳答案
你说得对:
Maybe
req.open("GET", url, true)
opened the ASP page from a cache
如果是通过 GET
请求,IE 将缓存 Ajax 响应。只需做这样的事情(这将使所有请求都有一个唯一的查询字符串,因此缓存不会成为问题):
req.open("GET", [url, "&_=", new Date().getTime()].join(""), true);
关于javascript - IE 部分页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8506606/