Rails 3:通过 jQuery 提交远程表单 - 防止页面重新加载
我的 Rails 表单如下所示:
- form_tag rel_references, :remote => true, :id=>"references_form", :method => 'get' do
= text_field_tag :rel_id, params[:rel_id], :id=>"reference_form_rel_id"
= submit_tag "Get references", :id => "referencesubmit"
我需要使用 jQuery 根据 DOM 元素的 HTML 动态填充文本字段 #reference_form_rel_id,然后从同一 jQuery 函数中(远程)提交此表单。这就是我正在做的:
$(".classname").live('click',function(){
var relationship_id = $('#id_store').html().trim();
$('#reference_form_rel_id').val(relationship_id); // populate the text field
$('#references_form').submit(); // submit the form
});
现在,表单确实被提交了,但是,它不是远程提交的,并且页面重新加载,从而违背了 :remote => 的目的。真的。请指导我如何通过 jQuery 正确提交 Rails 远程表单。 谢谢!
Here how my rails form looks like:
- form_tag rel_references, :remote => true, :id=>"references_form", :method => 'get' do
= text_field_tag :rel_id, params[:rel_id], :id=>"reference_form_rel_id"
= submit_tag "Get references", :id => "referencesubmit"
I need the textfield #reference_form_rel_id to be dynamically populated based on the HTML of a DOM element using jQuery and then submit this form (remotely) from within the same jQuery function. So this is what I am doing:
$(".classname").live('click',function(){
var relationship_id = $('#id_store').html().trim();
$('#reference_form_rel_id').val(relationship_id); // populate the text field
$('#references_form').submit(); // submit the form
});
Now, the form does get submitted, however, it is not submitted remotely, and the page reloads thus defeating the purpose of the :remote => true. Please guide me on how to correctly submit a rails remote form via jQuery.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试
you may try