Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...