下面的 ajax onreadstatechange() 被调用的情形很诡异,alert 输出
如下:
xhr.open:b.js
readyState=1
readyState=2
readyState=3
readyState=4
status=0
got alert("b.js")
status=0
got alert("b.js")
为什么重复了两次? firefox 3.5.9。
(function() {
var i, xhr;
try {
xhr = new XMLHttpRequest(); // Firefox, Opera, Safari
if (xhr.overrideMimeType) {
// avoid Firefox treating it as text/xml to report a syntax error
xhr.overrideMimeType('text/javascript; charset=UTF-8');
}
alert("<br/>xhr.open: b.js");
xhr.open('GET', "b.js", true);
xhr.onreadystatechange = function() {
alert("<br/>readyState=" + xhr.readyState);
if (xhr.readyState == 4) {
xhr.onreadystatechange = function() {};
i = xhr.status;
alert("<br/>status=" + i);
if (i == 200 || i == 0) {
script = xhr.responseText;
alert("<br/>got " + script);
}
}
}
xhr.send(null);
} catch (e) {
alert(e);
}
})()
--
FROM 114.249.125.*