Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

javascript - AJAX problem in IE9?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...