Home  >  Article  >  Backend Development  >  javascript - How does js limit the number of sliding loads during sliding loading?

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

WBOY
WBOYOriginal
2016-12-01 00:56:311463browse

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>

One is status lock, as mentioned above

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

Statement:
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