Answer the question
In order to leave comments, you need to log in
How to make a request when implementing the scroll-to-load functionality?
Hello. I'm trying to make a functional, scroll-load. Well, I'll write a script, in principle there is nothing difficult, we track the scrolling to the bottom and send an Ajax request. But how to query the database? Let's say we already have the first 10 items on the page, I need to load the next 10, if I send a simple request, it will insert the same 10
Answer the question
In order to leave comments, you need to log in
This approach, as suggested by @IgorO2 , will be a bottleneck in your system if it suddenly becomes highly loaded. It is much better to send not an offset, but the last record ID and build a query like this:
Depending on the sort order, the sign will need to be reversed.
Well, it is natural that in systems that respect themselves and their clients, we received only JSON from the server, and we will do all the templating on the client (we implement MVC, for example, through the backbone).
Well, keep a record count and, depending on the number of records, make a request withLIMIT count, 10
There are many implementations, it can be conditionally divided into 2:
1. A client-side template engine (js) is used, then you get json like:
{
items: [..],
offset: 10
}
<div id="content">
<div class="page">...</div>
<div class="page">...</div>
...
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question