function a (){
var b = null;
if(window.XMLHttpRequest) b = new XMLHttpRequest();
else if(window.ActiveXObject) b = new ActiveXObject("Microsoft.XMLHTTP");
if(!b) b = new ActiveXObject("msxml2.XMLHTTP");
return b;
}
var b=a();
function c(){
var u = "ajax3_php.php?w="+ parseInt(Math.random()*88888);
b.onreadystatechange = function (){
if(b.status == 200 && b.readyState == 4){
document.getElementById("divid").innerHTML = b.responseText;
}
}
b.open("get", u, true);
b.send();
}
And on the target page “ajax3_php.php”:
<?php
echo "OK";
?>
And on “divid” id
<div id=”divid”>Test</div>
the error message is:
Message: Unspecified error.
Line: 20
Char: 3
Code: 0
URI: http://localhost/lat1/ajax/ajax3.php
The shocking part is, this is on line 20:
if(b.status == 200 && b.readyState == 4){
What is wrong with that?
FYI : firebug says nothing.
This code seemed to do the trick.
I don’t have a silver bullet answer as to why the error was popping up, but the call to
b.statuswas throwing an error when thereadyStatewasn’t4. However, that particular error was one I ran into recently (but a different error type) when sending an empty string viainnerHTMLto an element in IE 8 (I suspected yourresponseTextwas empty, causing the error).I took the liberty of fixing that code for you (along with a few other touches). There are no errors in IE 7-8, Quirks or none.
I hope this helps you.
-Matt
EDIT: I stumbled upon this MSDN post. It’s curious to see that their example code uses nested if blocks just like I did, yet no explanation. I’ll investigate further.
Link: http://msdn.microsoft.com/en-us/library/dd576252%28v=vs.85%29.aspx