Rails remote link not working when loaded via AJAX

北城以北 提交于 2021-01-28 06:12:08

问题


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

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

Here is the partial for the link

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

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

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).

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?


回答1:


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.



来源:https://stackoverflow.com/questions/14078950/rails-remote-link-not-working-when-loaded-via-ajax

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