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 langua开发者_如何学运维ge="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?
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);
精彩评论