12

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
graup
  • 1,089
  • 1
  • 12
  • 20
  • Your js code would be handy. – ZippyV Apr 02 '13 at 19:45
  • *"The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, ***but they are not supported by all browsers***."* Maybe it's possible that Firefox doesn't support DELETE via AJAX? – Zeta Apr 02 '13 at 20:13
  • Is this a jQuery problem then? [This answer](http://stackoverflow.com/a/166501/700283) says all major browser should be able to do DELETEs (and that was years ago). – graup Apr 02 '13 at 20:15
  • 6
    Looks like you're trying to send an object and jQuery messes that up. Did you try JSON.stringify? – freddyb Apr 03 '13 at 11:38
  • Yep, that was it! I used JSON.stringify at most points but probably forgot it here. If you would post that as an answer, I'd happily accept it. – graup Apr 03 '13 at 11:43

4 Answers4

27

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.

graup
  • 1,089
  • 1
  • 12
  • 20
  • See [my answer](http://stackoverflow.com/a/26007157/8946); this happens for me with any request which is not GET and which supplies an empty object. – Lawrence Dol Sep 24 '14 at 01:34
8

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.

jbrios777
  • 191
  • 3
  • 9
  • "data": Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. [link](http://api.jquery.com/jquery.ajax/) – Jorj Jun 13 '14 at 08:25
  • This is my experience as well, but only for the POST method. Using x-www-form-urlencoded in a POST, processData: false causes a Firefox error. – wbdarby Aug 27 '14 at 21:20
1

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 "".

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
  • FYI, mithril.js now does the conversion to empty string. As of 0.1.23 it will also throw a friendlier error if you force it to be wrong (e.g. via a bad serialize option) – LeoHorie Nov 01 '14 at 02:05
0

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.

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55