问题
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:
you may try
$('#referencesubmit').trigger('click')
来源:https://stackoverflow.com/questions/9027282/rails-3-submit-remote-form-via-jquery-prevent-page-from-reloading