Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INVALID_STATE_ERR: DOM Exception 11 (WebKit)

I recently tested a Cappuccino app I was working on with Chrome and Safari. I get the error:

INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

The lack of information is frustrating. What object and where did I attempt to use it? Chrome tries to answer the second question but the line number it gives, 465, doesn't mean anything when the file it gives is just 94 lines long. Without more information I don't even know where to start looking.

like image 493
Regis Frey Avatar asked Aug 15 '10 18:08

Regis Frey


4 Answers

Usually this error occurs with the XMLHttpRequest when you call the open method with async = true, or you leave the async parameter undefined so it defaults to asynchronous, and then you access the status or responseText properties. Those properties are only available after you do a synchronous call, or on the readyState becoming ready (once the asynchronous call responds). I suggest you first try with async = false, and then switch to it being true and use the onReadyStateChange.

like image 93
Dave Lampert Avatar answered Nov 18 '22 07:11

Dave Lampert


In my case I was setting the headers prior to opening the connection. To prevent this error the headers need to be set after opening the connection:

var fd = new FormData();
fd.append("fileToUpload", file);
var xhr = new XMLHttpRequest();
xhr.open("POST", postUrl, true);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(fd);

I understand this answer is specific to my problem and not the generic INVALID_STATE_ERR: DOM Exception 11 message but figured I would post my solution here for the next person.

like image 24
Jeff Widmer Avatar answered Nov 18 '22 07:11

Jeff Widmer


Chrome canary offers stack traces for DOM Exceptions!

like image 8
Jamie Pate Avatar answered Nov 18 '22 05:11

Jamie Pate


This can also happen when Javascript tries to document.write() into an XHTML page (Content-Type: application/xhtml+xml).

like image 5
Brian DeRocher Avatar answered Nov 18 '22 06:11

Brian DeRocher