【发布时间】:2009-05-25 20:33:58
【问题描述】:
我正在尝试发送如下所示的 jQuery Ajax PUT 请求:
$.ajax({
type: "PUT",
url: '/admin/pages/1.json',
data: { page : {...} },
dataType: 'json',
success: function(msg) {
alert( "Data Saved: " + msg );
}
});
我的控制器大致如下:
respond_to do |format|
if @page.update_attributes params[:page]
format.html{ ... }
format.json{ render :json => {:saved => 'ok'}.to_json }
else
format.html{ ... }
format.json{ render :json => {:saved => 'fail'}.to_json }
end
end
但我收到以下错误。
评估 nil.name 时发生错误
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:29:in merge_element!'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:18:inparse'
(DELEGATION):2:in __send__'
(__DELEGATION__):2:inparse'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/hash/conversions.rb:154:in `from_xml'
...
...
就像 Ruby on Rails 试图将参数解析为 XML,但我想使用 JSON!
如何将 JSON 放入 Ruby on Rails?
【问题讨论】:
-
通过编辑而不是提出新问题来更新您的原始问题:stackoverflow.com/questions/907910/…
标签: jquery ruby-on-rails ajax json