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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:14:35  来源:igfitidea点击:

Uncaught Error: INVALID_STATE_ERR: DOM Exception 11

javascriptandroidcordovaxmlhttprequestdomexception

提问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 falsein 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::Statusis unavailable till the XMLHttpRequest::readyStatehas changed to 4ie. a proper response has been acquired from the server and has now been populated in the Statusvariable.

XMLHttpRequest::Status直到不可XMLHttpRequest::readyState更改为4IE浏览器。已从服务器获取正确响应并已填充到Status变量中。

Thus accessing the XMLHttpRequest::Status early can result in this error.

因此,提前访问 XMLHttpRequest::Status 可能会导致此错误。

Solution: first verify readyStateand 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!
    }
}