问题
I have a remote => true
form and would like to submit it AND avoid a submit method.
Usually i would do
form$.get(0).submit()
form$.submit(function(){..avoid going here..})
but this sends the form as html instead of js. Any way to do this and get js in response?
Thanks!
回答1:
Use this code in your controller
respond_to do |page|
page.js {}
end
and add a file in your view with controller's function name ending with .js extension.
回答2:
man that i was a pain to find.
the answer is replace
$(form).get(0).submit()
$(form)[0].submit()
by
$(form).trigger("submit.rails")
this will skip all submit even listeners except the rails one.
来源:https://stackoverflow.com/questions/12394814/rails-3-how-do-i-submit-a-remote-form-with-jquery-and-avoid-callbacks