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
Post a Comment