desandro / colcade

Lightweight masonry layout
488 stars 21 forks source link

Having trouble appending items via ajax #14

Closed babblebykev closed 6 years ago

babblebykev commented 6 years ago

I'm currently working on a pagination system for a site I'm making, where the posts on the next page would be loaded into the current page via AJAX. However, I'm currently having trouble getting the "append" function to work with the AJAX-loaded posts.

Code:

$.ajax({ type: "GET",   
         url: nextURL,   
        success: function(posts) {
            var nextPage = $(posts).find(".posts_inner").html();
            $(".posts_inner").colcade( 'append', nextPage );
            $(".posts .load").removeClass("active").find("span").text("Load more posts");
            $("body").getNiceScroll().resize();
        },
        error: function(posts){
            $(".posts .load").removeClass("active").addClass("none").find("span").text("No more posts");
}
});

Live link: design.bykev.co

desandro commented 6 years ago

I'm not exactly sure what the content of posts is, but if its a string of HTML, then you should wrap it in a jQuery object and use that with append



var $posts = $( posts );
$(".posts_inner").colcade( 'append', $posts );
babblebykev commented 6 years ago

Hello again,

It works as intended now. Thanks for the response!