[英]Partially page refreshing in IE
I need refresh a part of my page and I use this script which works in FF and Chrome, but this doesn't work 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')">
...
I thinked, that the problem was in setTimeout, but when I debuged the page, it looked works. 我以为问题出在setTimeout中,但是当我调试页面时,它看起来可行。 Maybe req.open("GET", url, true) opened the ASP page from a cache.
也许req.open(“ GET”,url,true)从缓存中打开了ASP页。 Could you help me?
你可以帮帮我吗?
Thank you 谢谢
L. L.
You're right when you say: 您说对了,这是对的:
Maybe
req.open("GET", url, true)
opened the ASP page from a cache也许
req.open("GET", url, true)
从缓存中打开了ASP页
IE will cache the Ajax response if it is via a GET
request. 如果是通过
GET
请求,则IE将缓存Ajax响应。 Just do something like this (which will make all requests have a unique query string so caching will not be an issue): 只需执行以下操作即可(这将使所有请求都具有唯一的查询字符串,因此缓存不会成为问题):
req.open("GET", [url, "&_=", new Date().getTime()].join(""), true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.