I was trying to follow: Rails: submit (via AJAX) when drop-down option clicked
However none of these options appear to work (onsubmit, submit)
This is what I currently have that is refreshing the page:
= simple_form_for task, :remote => true, :format => :js do |f|`
= f.association :status, :label => false, :include_blank => false, :input_html => {:onchange=>'this.form.submit();' }`
This simply posts the form regularly and causes the page to refresh.
How can I get it to post via ajax so the page won't refresh?
Just change your onchange
to this instead:
{:onchange=>'$(this.form).submit();' }
Although rails overrides the default action and submits via AJAX when you add :remote => true, you are forcing the form to post the regular what in your onchange event.
You need to make your own function to submit via AJAX and call that from your onchange, using $.post() $.post() to send the form to the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With