Answer the question
In order to leave comments, you need to log in
Where did I make a mistake in pagination via ajax?
I have a script in which pagination via ajax should be triggered when a button is clicked.
On the first press it works correctly, but on subsequent presses it does not work correctly.
function posts_pagination() {
const paginationBtn = $('.more-btn');
paginationBtn.each(function () {
$(this).click(function (e) {
alert('Работает');
e.preventDefault();
const clicked = $(this);
let page = clicked.children('span').text();
const limit = 5;
const offset = limit * (page - 1);
$.ajax({
type: 'POST',
url: 'php-scripts/posts.php',
dataType: 'html',
data: {
page: ++page
},
success: function (data) {
const main = $('.main');
clicked.remove();
main.append(data).append('<div class="more"><a href="#" class="more-btn">Далее >> <span style="display: none;"> ' + (page) + ' </span>');
}
});
});
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question