Dr. Lawlor's Code, Robots, & Things

April 29, 2013

Chrome JavaScript InvalidStateError: DOM Exception 11

Filed under: Programming — Dr. Lawlor @ 2:35 pm

There’s an annoyingly cryptic error message in Chrome when your JavaScript code does an XMLHttpRequest incorrectly–“Uncaught Error: InvalidStateError: DOM Exception 11”.  This error shows up when you access the request’s “status” inside onreadystatechange prior to hitting readyState 4.  Firefox doesn’t complain about this, and Chrome only seems to care if you’re doing it inside onreadystatechange.

For example, this works fine:

var req=new XMLHttpRequest();
req.onreadystatechange=function()
{
  if (req.readyState==4 && req.status==200)
  {
    document.getElementById("div1").innerHTML=req.responseText;
  }
};
req.open("GET","/",true);
req.send();

But interchanging the order of the req.readyState and req.status checks results in “Uncaught Error: InvalidStateError: DOM Exception 11”.

FYI!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: