function testAjax()
  {
   // 打开链接
xmlHttp.open("GET", "test.php", true);
// 服务器运行完后执行updatePage;
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
  }
  // 处理服务器返回
  function updatePage()
  {
    if(xmlHttp.readyState == 4)
{
  var response = xmlHttp.responseText;
          alert(response);
}
  }
  createXMLHttpRequest();test.php中的代码:
<?php
 echo rand(0,100);//我用的是PHP5.XX,也加srand试过,没用。
?>我用上面代码为什么当我点击按键时显示的都是同一个数?
而我直接打开test.php刷新每次的数是随机变化的。

解决方案 »

  1.   

    被ie缓存了你可以这样
    xmlHttp.open("GET", "test.php?.r=" + Math.rand() , true); 
      

  2.   

    谢谢楼上的解答,我还有个问题想顺便问下(嘿~~):
    我把text.php传来的数据设置为<div id="divAjax"></div>里面的内容.
    document.getElementById("divAjax").innerText = unescape(response);结果网页上是正常显示了,但我查看源码(IE页面右击:查看源文件)却发现HTML源码中的<div id="divAjax"></div>
    里面的内容并没有改变,这是怎么加事?
      

  3.   

    嗯,这个是正常的
    你查看到的源码是从服务器取回的html文件的内容你动态的添加修改是不会反映到这个文件中的。