jQuery $ .ajax无法在Firefox中抵御Rails(406响应)(在chrome& IE中有效) [英] jquery $.ajax not working in firefox against rails (406 response) (works in chrome & IE)
问题描述
我有一个rails后端,正在针对它测试以下jquery代码:
I have a rails backend and am testing the following jquery code against it:
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不可接受
This code works fine in Chrome and IE. However in Firefox (using Firebug), I see this: http://localhost:3000/notifications/detect_type.json 406 Not Acceptable
以下是日志中的Firefox请求:
处理中 NotificationsController#detect_type (对于127.0.0.1在2010-12-21 17:05:59) [POST]参数: {"action" =>"detect_type", "content" =>"226南艾默生丹佛 co 80209", "controller" =>"notifications"}用户 列(2.0ms)从显示字段
users
用户负载(37.4ms)选择 * FROMusers
WHERE(users
.id
='1')LIMIT 1在58ms内完成(查看: 1,DB:40)| 406不可接受[http://localhost/notifications/detect_type.json]
Processing NotificationsController#detect_type (for 127.0.0.1 at 2010-12-21 17:05:59) [POST] Parameters: {"action"=>"detect_type", "content"=>"226 south emerson denver co 80209", "controller"=>"notifications"} User Columns (2.0ms) SHOW FIELDS FROM
users
User Load (37.4ms) SELECT * FROMusers
WHERE (users
.id
= '1') LIMIT 1 Completed in 58ms (View: 1, DB: 40) | 406 Not Acceptable [http://localhost/notifications/detect_type.json]
以下是日志中的Chrome请求:
处理中 NotificationsController#detect_type (对于127.0.0.1在2010-12-21 17:06:41) [POST]参数:{"action" =>"detect_type", "content" =>"226南艾默生80209", "controller" =>通知"}
用户列(2.1ms)从users
显示字段 用户负载(30.4ms)
SELECT * FROMusers
WHERE(users
.id
='1')LIMIT 1已完成 在100ms(查看:1,DB:33)|
200 OK [http://localhost/notifications/detect_type.json]
Processing NotificationsController#detect_type (for 127.0.0.1 at 2010-12-21 17:06:41) [POST] Parameters: {"action"=>"detect_type", "content"=>"226 south emerson 80209", "controller"=>"notifications"}
User Columns (2.1ms) SHOW FIELDS FROMusers
User Load (30.4ms)
SELECT * FROMusers
WHERE (users
.id
= '1') LIMIT 1 Completed in 100ms (View: 1, DB: 33) |
200 OK [http://localhost/notifications/detect_type.json]
我很困惑.想法?
推荐答案
奇怪的是,解决方案是在导轨端进行此操作:
Oddly enough, the solution was to do this on the rails side:
format.js {
render :text => type.to_json
}
format.json {
render :json => type.to_json
}
jQuery错误?不确定...
JQuery bug? Not sure...
这篇关于jQuery $ .ajax无法在Firefox中抵御Rails(406响应)(在chrome& IE中有效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!