我正在使用Rails 3.1.1
我在haml视图中有以下内容:
= form_for booking.notes.build,:remote => true do |f|
= f.text_area(:content)
= f.hidden_field(:noteable_id)
= f.hidden_field(:noteable_type)
= f.submit('Add note')
这会在提交时创建新笔记.此外,我的控制器的响应正在Chrome控制台(网络标签)中正确显示.但我似乎无法抓住回应.
我想在提交后更新页面上的注释列表.我一直试图绑定到ajax响应,所以我可以抓住响应,但我失败了.例如,我认为这应该有效,但不是:
$('#new_note').bind('ajax:success',function() {
alert('Hi');
});
但是没有触发警报.我认为这解释了为什么这也行不通.
$('#new_note').bind("ajax:success",function(evt,data,status,xhr){
// Insert response partial into page below the form.
$(this).parent.append(xhr.responseText);
})
你能指点一下可能出现的问题吗?