php - 在加载 ajax 的页面内无限滚动

标签 php jquery html ajax

我有一个页面(我们称它为 1.php),它使用 jQuery-ajax 将 2.php 加载到一个 div-box 中。 2.php 从我的数据库中打印出 20 条记录。 当我滚动到 div-box 底部时,我希望它加载接下来的 20 条记录。 就像 Facebook、Twitter 等一样。

现在,我已经得到了这种行为,但只有在它自己加载 2.php 时才会这样! 但不在 div-box 内。

我该怎么做?

提前致谢!

最佳答案

文件 1.php 应该输出这个:

<div id="content">
</div>

<script type="text/javascript">
  $(document).ready(function() {
    // when we scroll, check the position:
    $(window).scroll(function()
    {
      // if at bottom, add new content:
      if  ($(window).scrollTop() == $(document).height() - $(window).height())
      {
        $.get("2.php",function(data) {
          $("#content").append(data);
        },'html');
      }

    }); 

  });
</script>

如果您想将迭代编号发送到 2.php,您可以在一些隐藏的输入中记住它并将它作为参数发送给 $.get()。

希望对您有所帮助。

关于php - 在加载 ajax 的页面内无限滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6164767/

相关文章:

javascript - 如何检测 DIV 的尺寸变化?

javascript - 在 jsp 中的 jquery 即时过滤器后,Html 选择不更改单击选项

javascript - 3 个复选框 1 独立于另一个需要 jquery 不将第一个作为集合的一部分

javascript - 应用组合转换时属性无效

c# - 如何从网页运行 Windows 应用程序?

php - 检查引用另一个表的表中的特定行?

php - 如何使用 MySQL 和 PHP 安全地删除向用户显示的行?

php - 如何用 PHP 操作这个 SQL?

javascript - 通过 JavaScript 使用 HTML 下拉列表值

jquery - 使用 jQuery 定位相对于鼠标单击位置的 div 元素