问题
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