javascript - AJAX pagination refreshes page every other link -


in rails app i'm using will_paginate , partials make can click through pages of list without page refreshing. js use call partials , all:

$(function () {       $('.pagination a').on("click", function () {           $.get(this.href, null, null, 'script');           return false;       });   });   

for reason, however, works fine when click link first time; replaces partial updated one. after that, click next pagination anchor link , page full refresh. idea why? thinking js executes when dom loaded , when partial replaced 1 containing new links aren't wired code. if correct, how go fixing it?

looks might have use event delegation... pagination ajax request might replacing .pagination a elements also, means newly created elements not have click handler registered.

so try

$(function () {       $(document).on("click", '.pagination a', function () {           $.get(this.href, null, null, 'script');           return false;       });   });   

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -