Fleegix.org

XMLHttpRequest and 0x80004005 (NS_ERROR_FAILURE) error

2006-10-21 10:13:00

I would have thought they'd have fixed this bug in Firefox by now, but I just ran into it again. I can remember bumping my head on this about a year and a half ago.

I have a pop-up window that invokes an XHR request to re-render its opener window (the window that spawns the pop-up), with a call like opener.doUpdateWithXHR() or whatever. It's supposed to pull down some content from the server and repaint the main window.

This works fine with the initial call, but if you close the pop-up window, all subsequent attempts to make requests with the same XHR object result in this little gem of an error: "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.open]" Has a sort of sparse elegance to it, I think.

This guy reports the same problem, but with calling XHR in the parent of an iframe that he removes. He points to a Mozilla bug for the issue, opened in ... July of 2004.

The workaround, of course, is to call your function in the opener/parent window through setTimeout, to force it to execute in the context of that window. Make a function in your main window like this:

function doUpdateWithXHRFromPopup() {
    setTimeout(doUpdateWithXHR, 0);
}

And call that function from your popup/iframe instead of referencing doUpdateFromXHR directly. (Another less-optimal workaround would be just to create a brand-new XHR object for the request.)

I wonder if or when they ever plan on fixing this. They still have it flagged as 'New' in Bugzilla. I know it's an Ajaxey, Web 2.0 world and all, but it's not like pop-ups/iframes and XHR are some sort of matter and anti-matter combination. You ought to be able to use the old stuff and the new stuff together without them going kerblooey.

About

This is the blog for Matthew Eernisse. I currently work at Yammer as a developer, working mostly with JavaScript. All opinions expressed here are my own, not my employer's.

Related

Previous posts

All previous posts ยป

This blog is a GeddyJS application.