I would like to know how to return the var page from the processed method, so next time I click on ".morePlease", it sends the new page value (incremented using my backend php returned and returned).
(function($) {
var page ='';
$(document).on( 'click', '.morePlease', function( event ) {
event.preventDefault();
getMorePosts(page);
})
function getMorePosts(page) {
$.ajax({
url: '<?=$ajaxUrl?>',
type: 'post',
data: {
action: 'ajax_pagination',
query_vars:'<?=$query?>',
page: page
}
}).done(function(response) {
var obj=$.parseJSON(response);
page = obj.page;
}).fail(function() {
alert( 'no result ' );
});
}
})(jQuery);
source
share