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();
  if (req.readyState==4 && req.status==200)

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


Blog at WordPress.com.