1、在服务端加 header("Cache-Control: no-cache, must-revalidate");  2、在ajax发送请求前加上 anyAjaxObj.setRequestHeader("If-Modified-Since","0");  3、在ajax发送请求前加上 anyAjaxObj.setRequestHeader("Cache-Control","no-cache");  4、在 Ajax 的 URL 参数后加上 "?fresh=" + Math.random(); //当然这里参数 fresh 可以任意取了
页头加入防缓存设置:
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">一般情况下,这里的XMLHttpRequest不会直接使用
你应该可以找到这样的代码
XXXXX.send(YYYYYY);
那么,就把它变成
XXXXX.setRequestHeader("If-Modified-Since","0");
XXXXX.send(YYYYYY);服务器端假如防缓存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
//=====================================================================
这些方法全用过 但是都不能彻底解决IE缓存的问题 只是部分解决 比如插入10条数据 只有6次能成功 4次是失败的 当然如果不加 只有刷新页面才会显示数据 大家有好的方法没?

解决方案 »

  1.   

    再加上
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      

  2.   

    ajax传个随机数过去看看,或者把时间戳传过去,上面你说的估计是因为插入操作过快
      

  3.   

    另外,可以帖出你的 ajax 代码吗?
      

  4.   

    ajax.jsfunction funadd() 

      
       createXMLHttpRequest(); 
       var url = 'for.php';
       var f = document.myform;
       var u_id = f.uid.value;
       var u_Content = f.replyContent.value;
       var postStr = "uid="+u_id+"&u_Content="+u_Content+"&num="+Math.round(Math.random()*10000); 
       xmlHttp.onreadystatechange = addChange;
       xmlHttp.open("POST", url, true);
       xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       xmlHttp.setRequestHeader("Cache-Control","no-cache"); 
       xmlHttp.setRequestHeader("If-Modified-Since","0");
       xmlHttp.send(postStr);
      
    } for.php
    <?php
    header('Content-Type:text/html;charset=utf-8');
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    ............................
    ?>
      

  5.   

    从代码上看,你的 xmlHttp 是全局的,只是导致失败的主要原因象你这样的写法,当前一次交互还没结束时你又调用 funadd 时,前一次的交互将被终止
      

  6.   

    ajax.jsvar xmlHttp; 
    function createXMLHttpRequest()

      if(window.ActiveXObject) 
       { 
         xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); 
       } 
       else if(window.XMLHttpRequest) 
       { 
         xmlHttp = new XMLHttpRequest(); 
       } 
    } function funadd() 

       
      createXMLHttpRequest(); 
      var url = 'for.php';
      var f = document.myform;
      var u_id = f.uid.value;
      var u_Content = f.replyContent.value;
      var postStr = "uid="+u_id+"&u_Content="+u_Content+"&num="+Math.round(Math.random()*10000); 
      xmlHttp.onreadystatechange = addChange;
      xmlHttp.open("POST", url, true);
      xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Cache-Control","no-cache"); 
      xmlHttp.setRequestHeader("If-Modified-Since","0");
      xmlHttp.send(postStr);
      
    } function addChange() 
    {
    if (xmlHttp.readyState == 4) 

             {
               if(xmlHttp.status == 200||xmlHttp.status == 0) 
                  { 
                     document.getElementById('msg').innerHTML = xmlHttp.responseText;
          
           } 
        else
            {
      alert("Sorry,服务器繁忙,请刷新页面稍后再试!");
    }
    }
    }又看了看书上的源码 也是声明了一个全局变量xmlHttp 我只是照猫画虎 能不能帮我修改下 谢谢!
      

  7.   

    看看我这个http://blog.csdn.net/xuzuning/article/details/5611305
      

  8.   

    说的对,应该用ajax的队列形式,前面回调后执行下一个.不然会阻塞或者终止..