Reputation: 3
My ajax script only works in Firefox and not ie why??
========================================
<html>
<head>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //retuen value
setTimeout("dochange('showResult')",5000);
}
if (!req.responseXML.documentElement && req.responseStream)
req.responseXML.load(req.responseStream);
}
};
req.open("GET", "ajax.php"); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
req.send(null); //send value
}
window.onLoad=dochange('showResult');
</script>
</head>
<body>
<div id="showResult"></div> <!–page result will be displayed here–>
</body>
</html>
Upvotes: 0
Views: 599
Reputation: 17713
Luke, use the Source! Better yet, use a proven JS library, e.g. jQuery. They deal with all of this cr*p and they do it better than you would ever have the time to do yourself.
Update:
Alex -- all kidding aside. The reason we are all telling you to use jQuery (or one of the other major Javascript libraries) is because getting this stuff to work on all (or even close to all) browsers is genuinely hard. As mangled as MS's handling of HTML and CSS is (and believe me, it sucks) their various implementations of JavaScript run the gamut from crap to huge-steaming-pile-of-crap. The various JS libraries give you standard, cross-browser ways of doing things -- stuff that it has taken real pros years to get right. You really, really don't want to waste your time on this stuff.
So, use a good library, get it working in Firefox using Firebug as your debugger, and you have a pretty good chance it will work in IE.
Upvotes: 4