javascript - How does js limit the number of sliding loads during sliding loading?

WBOY
Release: 2023-03-01 21:54:01
Original
1435 people have browsed it

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

Reply content:

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>
Copy after login

One is status lock, as mentioned above

There is another one called JS function throttling, go search it

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!