Answer the question
In order to leave comments, you need to log in
How to write infinite scroll for back end (node.js)?
Hello, I have a problem, when I make a request, the counter does not increase for me. Or how to make a request
module.exports.load = async (req, res) => {
const { id } = req.params
try {
let page = 2
const perPage = 50
/* eslint-disable no-console */
console.log(page)
const ticket = await tickets
.find({ id_catalog: id }, { date: 0, __v: 0 })
.limit(perPage)
.skip(perPage * page - perPage)
.sort({ number_tikets: 1 })
++page
return res.json(ticket)
} catch (e) {
return res.json(e)
}
}
Answer the question
In order to leave comments, you need to log in
It is not necessary to create separate modules, just pass an additional GET parameter, for example, ajax=1
Suppose you want to implement this on the products page, let's call it products .
app.get('/products', function (req, res) {
if (req.query.ajax = 1) { // Если есть get параметр ajax = 1
// Делаете что-то и возвращаете не целую страничку, а только то что нужно добавить
} else { // Если нет
// Делаете что-то и возвращаете целую html страничку
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question