我做了一个AJAX聊天室;它可以在chrome和FF中工作,但当然不能在IE中工作。下面是我的代码:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;
try {
ajaxRequest = new XMLHttpRequest();
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "pull.php", true);
ajaxRequest.send(null);
}
setInterval( "ajaxFunction()", 1000 );
//-->
</script>结果永远不会显示。我有一个名为AjaxDiv的div,如果对任何人有帮助的话。我做错了什么?这是一个bug吗?
发布于 2011-05-14 04:04:26
可能每次你请求的时候都会拖出一个缓存的副本。
在服务器上设置正确的缓存头
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Pragma: no-cache' ); 或者将查询字符串附加到get请求,如下所示
ajaxRequest.open("GET", "pull.php?ts=" + new Date().getTime(), true);https://stackoverflow.com/questions/5996702
复制相似问题