jquery $ .ajax无法在firefox中使用rails(406响应)(适用于chrome和IE)

我有一个rails后端,我正在测试以下jquery代码:

var content = $("#notification_content").val(); var data = new Object(); data.content = content; $.ajax({ url: "/notifications/detect_type.json", type:"POST", data: data, success: function(result ){updateTypeDropDown(result)}}); 

此代码在Chrome和IE中运行良好。 但是在Firefox(使用Firebug)中,我看到: http:// localhost:3000 / notifications / detect_type.json 406 Not Acceptable

这是日志中的firefox请求:

处理NotificationsController#detect_type(适用于127.0.0.1 at 2010-12-21 17:05:59)[POST]参数:{“action”=>“detect_type”,“content”=>“226 south emerson denver co 80209”, “controller”=>“notifications”}用户列(2.0ms)显示来自users字段用户负载(37.4ms)SELECT * FROM users WHERE(users.id =’1’)LIMIT 1在58ms内完成(查看:1,DB :40)| 406不可接受[http://localhost/notifications/detect_type.json]


这是日志中的chrome请求:

处理NotificationsController#detect_type(适用于127.0.0.1 at 2010-12-21 17:06:41)[POST]参数:{“action”=>“detect_type”,“content”=>“226 south emerson 80209”,“controller “=>” 通知“}
用户列(2.1ms)显示来自users字段
用户负载(30.4ms)
SELECT * FROM users WHERE( id =’1’)LIMIT 1在100ms内完成(查看:1,DB:33)|
200 OK [http://localhost/notifications/detect_type.json]

我很难过。 想法?

奇怪的是,解决方案是在轨道侧执行此操作:

 format.js { render :text => type.to_json } format.json { render :json => type.to_json } 

JQuery错误? 不确定…

基于快速搜索,看起来似乎406表示浏览器拒绝(在这种情况下为Firefox)接受从服务器为请求传递的内容类型。 (这是一个这样的解释。)

尝试配置Firefox以接受json。 根据这篇文章 ,看起来Firefox可能想要使用扩展…

UPDATE

由于这似乎是$ .ajax的直接使用,你应该能够在没有任何奇怪的Firefox客户端设置更改的情况下使用它。 尝试通过在init期间添加一个选项,明确地告诉jquery返回的数据类型是什么,如下所示:

dataType:“json”

有关详细信息,请参阅此处的相关jquery文档。