IE中部分页面刷新

Partially page refreshing in IE

本文关键字:刷新 分页 中部 IE      更新时间:2023-09-26

我需要刷新我的页面的一部分,我使用这个脚本在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,但当我调试页面,它看起来工作。也许需要。open("GET", url, true)从缓存中打开ASP页面。你能帮我吗?

谢谢

l .

你说得对:

可能req.open("GET", url, true)从缓存中打开了ASP页面

如果是通过GET请求,IE将缓存Ajax响应。只要做这样的事情(这将使所有请求都有一个唯一的查询字符串,这样缓存就不会成为问题):
req.open("GET", [url, "&_=", new Date().getTime()].join(""), true);