简体   繁体   中英

Page ready not firing on ajax load more posts

Hello I am using this code below to load posts underneath without having to reload the page. Bassicly my problem is when the posts are laoded underneath, none of my wordpress plugins are loaded. I think it's because the page ready is not fired again. I am not really a coder, just basic knowledge. Would anyone be able to help me get it working so that the page ready is fired and my wordpress plugins know to load? Here is the code I am using to load more posts and you can see it in action on my website

Website: http://www.awesomewasteofmoney.com/

Code:

<script type="text/javascript">
// Ajax-fetching "Load more posts"
$('.load_more_cont a').bind('click', function(e) {
    e.preventDefault();
    //$(this).addClass('loading').text('Loading...');
        $('.load_more_text a').html('Loading...');
    $.ajax({
        type: "GET",
        url: $(this).attr('href') + '#content',
        dataType: "html",
        success: function(out) {
            result = $(out).find('#content_inside .featured_box');
            nextlink = $(out).find('.load_more_cont a').attr('href');
                        //alert(nextlink);
            //$('#boxes').append(result).masonry('appended', result);
                    $('#content_inside').append(result);
            //$('.fetch a').removeClass('loading').text('LOAD MORE AWESOME STUFF');
                        $('.load_more_text a').html('LOAD MORE AWESOME STUFF');
                            $(document).trigger("ready");



            if (nextlink != undefined) {
                $('.load_more_cont a').attr('href', nextlink);
            } else {
                $('.load_more_cont').remove();
                                $('#content_inside').append('<div class="clear"></div>');
                //  $('.load_more_cont').css('visibilty','hidden');
                }

/*                    if (nextlink != undefined) {
                        $.get(nextlink, function(data) {
                          if($(data + ":contains('featured_box')") != '') {
                            //alert('not found');
                                                    $('.load_more_cont').remove();
                                                          $('#content').append('<div class="clear"></div>');  
                          }                 
                        });                        
                    }*/

        }
    });
});
</script>  

At the end of your ajax success function you could try this:

$("body").trigger('load');

This should trigger the load event on the document body as if the page just loaded. I'm not sure if the WP plugins will respond as you expect, but it's worth a shot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM