admin管理员组文章数量:1390443
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?
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?
Share Improve this question edited May 13, 2011 at 19:19 phihag 289k75 gold badges469 silver badges483 bronze badges asked May 13, 2011 at 19:17 user569322user569322 10- 4 Or you could use jquery/mootools, which'd reduce all that to about 2 lines. Rolling your own ajax handlers these days is too painful. – Marc B Commented May 13, 2011 at 19:19
- ive considered that option, but im more concerned if microsoft made a bug in such a widely-used product – user569322 Commented May 13, 2011 at 19:21
- 6 @Ken programmer.97things.oreilly./wiki/index.php/… – phihag Commented May 13, 2011 at 19:23
- 1 @Ken Can you provide a full working example? I copied your code and it works fine in IE9 (Windows7 x86): phihag.de/2011/so/ie9-ajax.html . And IE8 had quite a share of bugs, you may inadvertently send buggy IE8 code to IE9 too. – phihag Commented May 13, 2011 at 19:30
- 1 Post an example to jsfiddle jsfiddle is your friend – user120242 Commented May 13, 2011 at 19:32
1 Answer
Reset to default 5Probably 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);
本文标签: javascriptAJAX problem in IE9Stack Overflow
版权声明:本文标题:javascript - AJAX problem in IE9? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744587658a2614291.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论