Skip to content

Instantly share code, notes, and snippets.

@manhleo93
Created July 14, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manhleo93/5815c533f1a2dca0c99d8cab7a5d4a4a to your computer and use it in GitHub Desktop.
Save manhleo93/5815c533f1a2dca0c99d8cab7a5d4a4a to your computer and use it in GitHub Desktop.
jQuery(function($){
// $('.post-listing').append( '<button class="load-more">Load More</button>' );
// var button = $('.post-listing .load-more');
var page = 2;
var loading = false;
$('body').on('click', '.load-more', function(){
if( ! loading ) {
loading = true;
$(this).remove();
var data = {
action: 'be_ajax_load_more',
page: page,
query: beloadmore.query,
};
$.post(beloadmore.url, data, function(res) {
if( res.success) {
$('.post-listing').append( res.data );
// $('.post-listing').hide().append( res.data ).fadeIn(500); // to have fadeIn effect
// $('.post-listing').append( button );
page = page + 1;
loading = false;
} else {
// console.log(res);
}
}).fail(function(xhr, textStatus, e) {
// console.log(xhr.responseText);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment