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

xmlHttp.readyState 为什么不出来 4 ????
相关JS代码:
<script type="text/javascript">
var xmlHttp; //用于保存XMLHttpRequest对象的全局变量

//用于创建XMLHttpRequest对象
function createXmlHttp() 
{
  //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
  if (window.XMLHttpRequest) 
{
  xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式
  } 
else 
{
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
  }
}
function vote() 
{
  try
{
createXmlHttp(); //创建XmlHttpRequest对象
  xmlHttp.onreadystatechange = showRating; //设置回调函数
  xmlHttp.open("POST", "wqx.html", true);
  xmlHttp.send(null);
}
catch(e)
{
alert("2");
}
}

function showRating() {
  if (xmlHttp.readyState == 4) 
{

  document.getElementById("form1").innerHTML =xmlHttp.responseText;
  }
else
{
alert(xmlHttp.readyState);
}
}
</script>


测试了下,只弹出 1,2,3 可就是没有 4
为什么?

------解决方案--------------------
缓存问题,加时间戳

xmlHttp.open("POST", "wqx.html?ts="+new Date().toString(), true);