我有一个页面(我们称它为 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/