日期:2014-05-16  浏览次数:20425 次

[急急急!!!]奇怪的xmlhttp问题
<script language="javascript" >  
var xmlhttp = false;  
function init(){  
 window.setInterval(startRequest, 2000);  
 return false;  
}  

function createXMLHttpRequest() {  
if (window.ActiveXObject){  
try{  
 xmlhttp=new ActiveXObject(\"Msxml2.XMLHTTP\");  
}  
catch(e){  
try{  
 xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");  
}  
catch(e){}  
}  
} else if (window.XMLHttpRequest) {  
xmlhttp=new XMLHttpRequest();  
if(xmlhttp.overrideMimeType){  
  xmlhttp.overrideMimeType("text/xml");  
 }  
}  

//异常,创建对象失败  
if(!xmlhttp){  
  window.alert("不能创建XMLHttpRequest对象实例!");  
  return false;  
 }  
}  
function startRequest() {  
var url = "myurl";  
createXMLHttpRequest();  
xmlhttp.open("GET", url, false);  
if (navigator.userAgent.indexOf(\"MSIE\") != -1) { 
  xmlhttp.onreadystatechange = processRequest; //IE 
} else { 
  xmlhttp.onreadystatechange = processRequest(); //Netscape FF 

xmlhttp.send(null);  
}  

function processRequest() {  
  alert("readyState:"+xmlhttp.readyState+""); //得到的总是1!! 
if (xmlhttp.readyState == 4){  
  if (xmlhttp.status == 200){  
  feedlist();  
  }  
}  
}  
function feedlist() {  
var xmlString = xmlhttp.responseText;  
document.getElementById("show_area").innerHTML = xmlString;  
}  
</script >

------解决方案--------------------
function startRequest() {
var url = "myurl?time="+ (new Date()).getTime();  
createXMLHttpRequest();
xmlhttp.open("GET", url, false);
if (navigator.userAgent.indexOf(\"MSIE\") != -1) { 
  xmlhttp.onreadystatechange = processRequest; //IE 
} else { 
xmlhttp.onreadystatechange = processRequest(); //Netscape FF 

xmlhttp.send(null);
}
兄弟,你的问题还没解决呢啊,会不会是浏览器缓存的问题,你加个时间戳试试看吧。