简体   繁体   中英

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.

<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. Maybe req.open("GET", url, true) opened the ASP page from a cache. Could you help me?

Thank you

L.

You're right when you say:

Maybe req.open("GET", url, true) opened the ASP page from a cache

IE will cache the Ajax response if it is via a GET request. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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