通过AJAX加载时,Rails远程链接不起作用 [英] Rails remote link not working when loaded via AJAX

查看:67
本文介绍了通过AJAX加载时,Rails远程链接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜这个问题类似于

I guess this question is similar to this one, but asking again as it has not yet been answered.

在我的rails应用程序中,我有一个视图,其中包含一个链接列表,这些链接通过ajax加载内容.

In my rails application, I have a view that contains a list of links that load content via ajax.

这是链接的部分内容

<%= link_to(story.title, {:controller=>"story", :id=>story.id}, :remote => true , :method=>'get', :class=>'story-link') %>

当通过HTTP加载视图时,此远程链接可以正常工作并通过AJAX加载内容.

This remote link works fine and loads content via AJAX when the view is loaded via HTTP.

该视图还具有一个小的远程表单,该表单在提交后会导致将新链接添加到该视图.但是,由于此新链接是通过AJAX加载的,因此不起作用(即,不通过AJAX加载内容).

The view also has a small remote form which upon submission results in a new link added to the view. However, as this new link is loaded via AJAX, it does not work (i.e. does not load content via AJAX).

此外,当我在浏览器中刷新视图时,新链接可以正常工作.我相信当通过AJAX加载链接时,不会发生适当的事件绑定.我该如何解决这个问题?

Moreover, when I refresh the view in the browser the new link works fine. I believe that the appropriate event binding does not take place when the link is loaded via AJAX. How can I solve this problem?

推荐答案

您要么需要使用

You either need to use delegated event handling for the form submission js, or re-register the form submission event(s) when the content is reloaded.

这篇关于通过AJAX加载时,Rails远程链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆