简体   繁体   English

每当用户点击页面底部时,如何迭代此函数以进行ajax调用?

[英]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. 发生ajax调用,并且更多数据被加载到页面上。 However, the ajax call does not happen when the user reaches the bottom of the page again. 但是,当用户再次到达页面底部时,ajax调用不会发生。 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? 如果是这样,每当用户到达页面底部时,我应该添加什么来进行ajax调用? I appreciate your input. 感谢您的投入。

This has been answered here: 这已经在这里得到回答:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AJAX请求在每个页面上都命中服务器,而我找不到该原始AJAX调用的来源 - AJAX request hits server from every page and I can't find the source of that original AJAX call 每次用户单击按钮时,如何将字段组添加到表单中? - How can I add group of fields to my form every time user hits a button? 每次用户被定向到视图/页面时,如何让我的 Javascript 不弹出 - How can I make my Javascript not pop up every time a user gets directed to the a View/Page 每次刷新页面时如何加载用户? - How can I load user every time the page is refreshed? 用户单击选项卡时如何进行Ajax调用? - How can I make an ajax call when user clicks on a Tab? 如何在每个页面请求时发送一​​个 ajax 调用并使用 ajax 调用的结果对 DOM 进行更改? - How do I send a make an ajax call when on every page request and make changes to the DOM with the results of the ajax call? 自动滚动到达页面底部后,如何在页面中循环url数组? - how can I loop url arrays in a page after the autoscroll hits the bottom part of the page? 我怎样才能重写这段代码,使 object 从 canvas 的顶部掉落,当到达底部时它会重置到顶部 - how can i rewrite this code to make an object fall from top of canvas and when hits bottom it resets at top 当用户点击页面底部时的jQuery - Jquery when the user hits bottom of the page 如何在每个设备上同时每隔30秒调用一次功能? - How can I call function every 30 seconds on every devices in the same time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM