最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 - Stack Overflow

programmeradmin1浏览0评论

I am getting the below error.

Uncaught Error: INVALID_STATE_ERR: DOM Exception 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?

I am getting the below error.

Uncaught Error: INVALID_STATE_ERR: DOM Exception 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?

Share Improve this question edited Mar 3, 2013 at 17:08 Josh Unger 7,1637 gold badges37 silver badges55 bronze badges asked Aug 22, 2012 at 11:41 AnildharaAnildhara 1971 gold badge2 silver badges7 bronze badges 2
  • Are you sending your request to the same server that served the page? Remember CORS! – tkone Commented Aug 22, 2012 at 11:45
  • My request is going on two server. One is our server (middle layer) and second one is expedia Server(a hotel booking API). Our middle layer sends further to expedia and return response to us. – Anildhara Commented Aug 22, 2012 at 11:47
Add a comment  | 

3 Answers 3

Reset to default 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.

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.

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

Solution: first verify readyState and only upon success — access 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!
    }
}

Socket has not be configure/initialize/opened connection and send has been called

发布评论

评论列表(0)

  1. 暂无评论