我有以下代码:
// setup the AJAX request
var pageRequest = false;
if(window.XMLHttpRequest) pageRequest = new XMLHttpRequest();
else if(window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
// callback
pageRequest.onreadystatechange = function() {
alert('pageRequest.readyState: ' + pageRequest.readyState
+ '\npageRequest.status: ' + pageRequest.status);
}
pageRequest.open('POST','ajax.php',true);
// q_str contains something like 'data=value...'
pageRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
pageRequest.setRequestHeader("Content-length", q_str.length);
pageRequest.setRequestHeader("Connection", "close");
pageRequest.send(q_str);
这在 Chrome 中运行良好,但 IE 卡住了它,吐出“未指定的错误”。它指向带有 alert() 的行。为什么不能显示警报?
编辑:好的,在我关闭错误对话框后,我得到了预期的三个警报......
编辑:现在它真的变得很奇怪。如果我改变
alert('pageRequest.readyState: ' + pageRequest.readyState
+ '\npageRequest.status: ' + pageRequest.status);
至
alert('pageRequest.readyState: ' + pageRequest.readyState);
然后它起作用了,我收到了 5 个警报。(1,1,2,3,4)