我想编写一个函数来完成一个简单的任务。我有10页数据,每一页有20条记录。当用户滚动到第一页底部并点击“加载更多”时,我想要加载第二页的数据,并将这些数据“追加”到第一页显示的数据中。
我找到了一个叫做infinitescroll的jquery插件。它对我来说工作得很好,除了我无法追加新的数据。
我的HTML代码:
这段文字是关于网页开发的。翻译如下:
任何信息都受欢迎,谢谢。
我找到了一个叫做infinitescroll的jquery插件。它对我来说工作得很好,除了我无法追加新的数据。
我的HTML代码:
<html>
<head>
<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.infinitescroll.js"></script>
<script type="text/javascript">
$(document).ready(function () {
console.log({
{
$p - > getCurrentPage()
}
});
var $container = $('#masonny-div');
$container.infinitescroll({
loading: {
msg: null,
msgText: "<em>Loading the next set of posts...</em>",
speed: 'fast',
},
navSelector: "#next",
nextSelector: "#next a",
itemSelector: "#masonny-div",
});
});
</script>
</head>
<body>
<div id='masonny-div'>
@foreach ($p as $x)
<div class="item">{{$x -> name}}</div>
@endforeach
</div>
<br>
<div id="next">
<a href="{{$p->getUrl($p->getCurrentPage() + 1)}}">Next</a>
</div>
</body>
</html>
这段文字是关于网页开发的。翻译如下:
这里是链接到下一页的地址:$p->getUrl($p->getCurrentPage() + 1
每次我点击它时,都会获得下一页的数据,但是我该如何将其附加到上一页呢?
我尝试调用回调函数,但这种方法并不起作用。控制台中没有任何消息。
var $container = $('#masonny-div');
$container.infinitescroll({
loading: {
msg: null,
msgText: "<em>Loading the next set of posts...</em>",
speed: 'fast',
},
navSelector: "#next",
nextSelector: "#next a",
itemSelector: "#masonny-div",
}, function(data){
console.log('I am here!');
console.log(data);
});
任何信息都受欢迎,谢谢。