Rails 3: submit Remote form via jQuery - prevent p

2019-06-11 14:58发布

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!

1条回答
闹够了就滚
2楼-- · 2019-06-11 15:35

you may try

$('#referencesubmit').trigger('click')
查看更多
登录 后发表回答