简体   繁体   中英

How can I iterate this function to make the ajax call every time the user hits the bottom of the page?

I am trying to implement the following for infinite scroll on my page.

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - 350) {
         //ajax call happens here
     }

All goes well when the user reaches the bottom of the page for the first time. The ajax call happens and more data is loaded onto the page. However, the ajax call does not happen when the user reaches the bottom of the page again. So my question is, does this function iterate every time the user reaches the bottom of the page or does it happen only once? If so, what should I add to make the ajax call every time the user reaches the bottom of the page? I appreciate your input.

This has been answered here:

https://stackoverflow.com/a/3898152/6265633

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("bottom!");
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM