問題描述
我正在使用 Django 構建一個 Web 應用程序.我通過 Ajax (jQuery v1.8.3) 在 Javascript 中有一堆 API 調用.
I'm building a web app with Django. I have a bunch of API calls in Javascript via Ajax (jQuery v1.8.3).
它們中的大多數都有效,但特定的一個會導致返回對象的狀態為 0,并且此消息作為 statusText:
Most of them work, but a particular one results in a return object with status 0 and this message as the statusText:
[Exception...'JavaScript 組件沒有名為:available"'的方法,調用方法時:[nsIInputStream::available]"nsresult:0x80570030(NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)"位置:JS 框架:: http://127.0.0.1:8000/media/js/jquery.js :: .send :: line 8434" 數據:無]
jQuery中對應的行是xhr.send((s.hasContent && s.data)|| null);
The corresponding line in jQuery is xhr.send( ( s.hasContent && s.data ) || null );
但是,這只發生在 Firefox 中.鉻工作正常.同樣,其他請求確實有效.唯一讓這個與眾不同的是 DELETE http 方法.
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.
請求如下(Chrome 中顯示的 HTTP 網絡數據 - Firebug 在 Firefox 中不顯示任何內容):
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.
JS 代碼是(在斷點處直接取自 Firebug Watch):
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);
我也曾嘗試禁用 FF 中的所有擴展.我運行 v20.0.
I also did try to disable all extensions in FF. I run v20.0.
推薦答案
問題是 Firefox 與 jQuery/XMLHttpRequest 的組合以及通過 HTTP DELETE 發送對象.一旦通過 JSON.stringify()
對對象進行 JSON 化,一切正常.
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.
不過,Firefox 會拋出一個奇怪的異常.
Still, a strange exception for Firefox to throw.
感謝 freddyb 的這個想法.
Thanks to freddyb for that idea.
這篇關于Firefox 異常'JavaScript 組件沒有名為:“可用"的方法'的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!