简体   繁体   English

表单提交后如何捕获Rails Controller操作完成

[英]How to catch Rails controller action completion after form submit

I have a form_tag <%= form_tag(recommend_path, :method => "get", :id => "form") do %> which works fine and redirects to the next page (recommend_path). 我有一个form_tag <%= form_tag(recommend_path, :method => "get", :id => "form") do %>可以正常工作并重定向到下一页(recommend_path)。 The Recommend controller (page to be loaded after form submission (non-Ajax) has some very long analysis action (takes ~10s) before the next page loads. 推荐控制器(表单提交后要加载的页面(非Ajax))在加载下一页之前具有很长的分析动作(大约需要10秒钟)。

What I am trying to achieve is to add an overlay with a loader while the Controller action is being done. 我要实现的目的是在完成Controller动作时使用加载程序添加一个叠加层。 I've added the overlay with a loader with success but it lasts only until form submit completion. 我已经使用成功的加载器添加了叠加层,但是它只能持续到表单提交完成为止。 To put it simply, after clicking the submit button, the overlay with a loader gets activated as desired but disappears after form submit completion (which takes only 1-2s) and the form page stays still for several seconds (while controller action being done) before moving to the next page. 简而言之,单击提交按钮后,带有加载器的叠加层会按需激活,但在表单提交完成后(仅需要1-2秒)消失,并且表单页面将保持静止几秒钟(在完成控制器操作时)移至下一页之前。

I would like to catch that controller action completion with JavaScript(JQuery) or anything else so that the overlay with a loader stays until the next page loads. 我想用JavaScript(JQuery)或其他任何内容捕获该控制器动作的完成,以便带有加载程序的叠加层一直保留到下一页加载为止。

Note: I am using TurboLinks. 注意:我正在使用TurboLinks。

Set in form html params like this: 设置如下形式的html参数:

 html: {remote: true, id: 'form'}

And caught it with Javascript : 并用Javascript捕获了它:

$('#form').on('ajax:complete', function(e, response){
# todo
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM