Home > Article > Backend Development > javascript - How does js limit the number of sliding loads during sliding loading?
When the user slides up to load more data, due to the slow network speed or slow return of data from the server, how to limit the sliding times to only load the paginated data once? How to implement the code
When the user slides up to load more data, due to the slow network speed or slow return of data from the server, how to limit the sliding times to only load the paginated data once? How to implement the code
Then request the data to return successfully and render it to the page, then add 1 to the page number
This is also a basic requirement to prevent repeated submissions
You set a variable as a status lock such as is_post = 0
, set it to 1 when pulling up to request data, at this time the pulling up will no longer issue a request, and wait until a request data comes back completely , and then set it to 0.
You need throttle/debounce
. I found an article for you: http://www.css88.com/archives...
Choose according to your actual situation, Lodash/Underscore has ready-made methods to use.
Set a flag, haha.
Give me an example
<code>var loading = false; nextPage(1); function nextPage(page) { if (loading) return; loading = true; $.ajax({ // .... success: function() { loading = false; } }) }</code>
One is status lock, as mentioned above
There is another one called JS function throttling, go search it