rails 3 how do i submit a remote form with jquery and avoid callbacks

允我心安 提交于 2019-12-13 05:57:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!