Я пытаюсь установить лимит отображаемых постов с помощью ajax, все вроде нормально, но когда я нажимаю кнопку с идентификатором loadMore, я все равно вижу те же посты.Я не очень понимаю, где я допустил ошибку.Кто-нибудь знает, как решить эту проблему.Буду благодарен за любые подсказки.
router.get("/blog", (req, res, next) => {
Post.find({})
.skip(0)
.limit(10)
.then(allPost => {
if (allPost) {
res.render("blog/index", {
Post: allPost,
moment: moment
});
} else {
return res.redirect("/");
}
})
.catch(err => {
console.error(err);
});
});
router.get("/api/blog", (req, res, next) => {
const page = req.query.page || 1;
const perPage = 10;
Post.find({})
.skip(perPage * page - perPage)
.limit(perPage)
.then(allPost => {
res.render("blog/posts", {
Post: allPost,
moment: moment
});
});
});
============================== *
$(document).ready(function($) {
$("#loadMore").on("click", function(e) {
e.preventDefault();
e.stopPropagation();
console.log("click");
$.ajax({
type: "GET",
url: "/api/blog?page=2",
complete: function() {
console.log("process complete");
},
success: function(data) {
$("#posts").append(data);
},
errorinu: function() {
console.log("process error");
}
});
});
});