七度&光 2011-05-13 19:17 采纳率: 100%
浏览 25

IE9中的AJAX问题?

I have made an AJAX chatroom; and it works in chrome and FF, but of course, not in IE. Here's my code:

<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
    var ajaxRequest; 
    try {
      ajaxRequest = new XMLHttpRequest();
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
           ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e){
           alert("Your browser broke!");
           return false;
     }
  }
    }

    ajaxRequest.onreadystatechange = function(){
      if(ajaxRequest.readyState == 4) {
        var ajaxDisplay = document.getElementById('ajaxDiv');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;
      }
    }

    ajaxRequest.open("GET", "pull.php", true);
    ajaxRequest.send(null);  
}

setInterval( "ajaxFunction()", 1000 );

//-->
</script>

The result never displays. I have a div named AjaxDiv if that helps anyone. What am I doing wrong? Is this a bug?

  • 写回答

1条回答 默认 最新

  • weixin_33695450 2011-05-13 20:04
    关注

    Probably yanking out a cached copy every time you make a request.

    Either set the correct caching headers on the server

    header( 'Cache-Control: no-store, no-cache, must-revalidate' );
    header( 'Pragma: no-cache' ); 
    

    Or append a query string to the get request like the following

    ajaxRequest.open("GET", "pull.php?ts=" + new Date().getTime(), true);
    
    评论

报告相同问题?