Simple Wordpress AJAX pagination

前端 未结 2 2031
眼角桃花
眼角桃花 2020-12-05 06:18

I\'m using the loop + jQuery below to load in the next set of pages, and it works on the first click, but when the next page is loaded in and I click on \"newer posts\" it r

2条回答
  •  北海茫月
    2020-12-05 06:50

    You're using jQuery's load() method to insert content, which is a shortcut for $.ajax, which of course inserts the content dynamically.

    Dynamic content requires delegation of the events to a non-dynamic parent, something jQuery makes easy with on()

    jQuery(function($) {
        $('#content').on('click', '#pagination a', function(e){
            e.preventDefault();
            var link = $(this).attr('href');
            $('#content').fadeOut(500, function(){
                $(this).load(link + ' #content', function() {
                    $(this).fadeIn(500);
                });
            });
        });
    });
    

提交回复
热议问题