javascript 未捕获的错误:INVALID_STATE_ERR:DOM 异常 11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12072315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
提问by Anildhara
I am getting the below error.
我收到以下错误。
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
未捕获的错误:INVALID_STATE_ERR:DOM 异常 11
Here is the code where I am getting Error RUN TIME.
这是我收到错误运行时间的代码。
xhttp.setRequestHeader("Content-type","application/xhtml+xml");<br>
xhttp.open("POST",xmlFile,true);<br>
xhttp.send(postData);
I tried with false
in the third parameter of xhttp.open.
Can anyone tell me what's causing this?
我false
在 xhttp.open 的第三个参数中尝试过。
谁能告诉我这是什么原因造成的?
回答by Anonymous
The error comes from the order of execution:
错误来自执行顺序:
xhttp.open("POST",xmlFile,true);
xhttp.setRequestHeader("Content-type","application/xhtml+xml");
xhttp.send(postData);
You must first open the connection and then set the request header otherwise you will get the error.
您必须首先打开连接,然后设置请求标头,否则您将收到错误消息。
回答by Ujjwal Singh
The XMLHttpRequest::Status
is unavailable till the XMLHttpRequest::readyState
has changed to 4
ie. a proper response has been acquired from the server and has now been populated in the Status
variable.
该XMLHttpRequest::Status
直到不可XMLHttpRequest::readyState
更改为4
IE浏览器。已从服务器获取正确响应并已填充到Status
变量中。
Thus accessing the XMLHttpRequest::Status early can result in this error.
因此,提前访问 XMLHttpRequest::Status 可能会导致此错误。
Solution: first verify readyState
and only upon success — access Status
解决方案:首先验证readyState
,只有在成功-访问Status
if (xmlhttp.readyState==4)
{
switch (xmlhttp.status)
{
case 200: // Do the Do
break;
case 404: // Error: 404 - Resource not found!
break;
default: // Error: Unknown!
}
}