未捕获的错误:INVALID_STATE_ERR:DOM异常11

时间:2022-11-20 20:29:16

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.

这是我得到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?

我在xhttp.open的第三个参数中尝试使用false。有谁能告诉我是什么原因造成的?

2 个解决方案

#1


22  

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.

您必须先打开连接,然后设置请求标头,否则您将收到错误。

#2


1  

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即。已从服务器获取正确的响应,现在已在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并且仅在成功时 - 访问状态

if (xmlhttp.readyState==4)
{
    switch (xmlhttp.status)
    {
    case 200: // Do the Do
        break;
    case 404: // Error: 404 - Resource not found!
        break;
    default:  // Error: Unknown!
    }
}

#1


22  

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.

您必须先打开连接,然后设置请求标头,否则您将收到错误。

#2


1  

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即。已从服务器获取正确的响应,现在已在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并且仅在成功时 - 访问状态

if (xmlhttp.readyState==4)
{
    switch (xmlhttp.status)
    {
    case 200: // Do the Do
        break;
    case 404: // Error: 404 - Resource not found!
        break;
    default:  // Error: Unknown!
    }
}