Firefox exception 'JavaScript component does n

2019-01-18 12:18发布

问题:

I'm building a web app with Django. I have a bunch of API calls in Javascript via Ajax (jQuery v1.8.3).

Most of them work, but a particular one results in a return object with status 0 and this message as the statusText:

[Exception... "'JavaScript component does not have a method named: "available"' when calling method: [nsIInputStream::available]" nsresult: "0x80570030 (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)" location: "JS frame :: http://127.0.0.1:8000/media/js/jquery.js :: .send :: line 8434" data: no]

The corresponding line in jQuery is xhr.send( ( s.hasContent && s.data ) || null );

However, this occurs only in Firefox. Chrome works fine. Again, other requests do work. The only thing which sets this one apart is the DELETE http method.

The request is as follow (HTTP network data shown in Chrome – Firebug doesn't show anything in Firefox):

Request URL: http://127.0.0.1:8000/api/reservation/13/
Request Method: DELETE
Status Code: 400 BAD REQUEST    (This is expected)

Request Headers
Accept: application/json, text/javascript, */*; q=0.01
Content-Length: 15
Content-Type: application/json
Origin: http://127.0.0.1:8000
Referer: http://127.0.0.1:8000/reservation/
X-Requested-With: XMLHttpRequest

Request Payload
[object Object]

Response Headers
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Date: Tue, 02 Apr 2013 19:18:35 GMT
Server: WSGIServer/0.1 Python/2.7.2

On the server, I don't receive any request.

The JS code is (taken directly from Firebug Watch at breakpoint):

options = {
    contentType: "application/json",
    data: Object {},
    dataType: "json",
    processData: false,
    type: "DELETE",
    url: "/api/reservation/13/",
    error: function(),
    success: function()
};
$.ajax(options);

I also did try to disable all extensions in FF. I run v20.0.

回答1:

The problem was a combination of Firefox with jQuery/XMLHttpRequest and sending an object via HTTP DELETE. Once JSON'ifying the object via JSON.stringify() everything worked.

Still, a strange exception for Firefox to throw.

Thanks to freddyb for that idea.



回答2:

The problem was with the property called processData within the $.ajax function. When this property is supplied as "false" (don't know why) Firefox doesn't like it, and as consequence, the browser doesn't digest the JSON request/response package. Chrome and Safari works just fine.



回答3:

This happens (as of 2014 with FireFox 32) with any non-GET AJAX request when the request data object is an empty object, like {}. I am using Mithril.js and it may be related to the fact that Mithril always sets a Content-Type for non-GET requests. This was absolutely repeatable once I knew the trigger.

(Note that the "non-GET" part may not be entirely accurate -- Mithril ignores the data object if it's a GET so sending an empty object with GET using the underlying AJAX object may also fail in the same way.)

Counter-intuitively, setting data to an empty string, "", does not fail in this way, so that was my work-around. I actually don't set data at all when there is none, and if it's unset by the time I send the request (in my AJAX wrapper) I default it to "".



回答4:

It sounds like you have a buggy Firefox extension installed which is trying to examine the XMLHttpRequest data and failing....

I suggest you try http://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode or just disabling whatever Firefox extensions are involved.