繁体   English   中英

IE中的部分页面刷新

[英]Partially page refreshing in IE

我需要刷新页面的一部分,并且使用此脚本,该脚本在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.

您说对了,这是对的:

也许req.open("GET", url, true)从缓存中打开了ASP页

如果是通过GET请求,则IE将缓存Ajax响应。 只需执行以下操作即可(这将使所有请求都具有唯一的查询字符串,因此缓存不会成为问题):

req.open("GET", [url, "&_=", new Date().getTime()].join(""), true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM