有4种方法可以解决这个问题:
1.在请求的URL后面加一个时间参数,如:time=new date(); 当然也可以添加其他性质参数,只要是随机参数就可以,open("GET",url+"?t="+Math.random(),false).或者url+"?timeStamp="+new Date().getTime();
2.
js 代码
function ajaxRead(file){
var xmlObj = null;
if(window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
return;
}
xmlObj.onreadystatechange = function(){
if(xmlObj.readyState == 4){
processXML(xmlObj.responseXML);
}
else{
document.getElementById ('playernews').innerHTML='采用AJAX来实现数据的读取,正在加载...';
}
}
xmlObj.open ('GET', file, true);
xmlObj.send ('');
}
function show() {
ajaxRead('*.jsp');
setInterval("ajaxRead('new.php')",30000); //自动更新
}
3.加上xmlhttp.setRequestHeader("Cache-Control","no-cache");
4.在XmlHttpRequest发送请求之前加上XmlHttpRequest.setRequestHeader("If-Modified-Since","0"),如:在XXXXX.send(YYYYYY); 之前

