请帮忙增加一下下滑自动传递并且获取第2页数据的功能?
ycwww 2018-01-24 10:35:01 【 我是新手,请大侠尽可能在源码上修改后贴上来,不胜感谢】
请求:
1.页面打开后,第一次自动获取第一页的数据。
2.下滑到底部后,自动向后加一页,传递,获取返回数据,增加到html上
[code=C]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="jquery-1.11.1.min.js"></script>
<script>
$(window).scroll(function () {
//已经滚动到上面的页面高度
var scrollTop = $(this).scrollTop();
//页面高度
var scrollHeight = $(document).height();
//浏览器窗口高度
var windowHeight = $(this).height();
//此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
if (scrollTop + windowHeight == scrollHeight) {
// alert('页面到底部了');
}
});
$(document).ready(function(){
// window.onload=function()
$("#button1").click(function(){
$.ajax({
type: "Get",
url: "Search.asp?page=1", //传递ajax获取页面
dataType: "json",
// 请求发送之前(发送请求前可修改XMLHttpRequest对象的函数,如添加自定义HTTP头。)。
beforeSend:function(XMLHttpRequest){
$("#Loading").html("正在加载中,请稍等···");
},
success: function (data) {
for (var i = 0, j = data.length; i < j; i++)
$('#all').append('<li>' + data[i].LogID + '|' + data[i].LogTitle + '</li>');
},
// 请求完成后的回调函数 (请求成功或失败之后均调用)
complete:function(XMLHttpRequest,textStatus){
$("#Loading").empty();
},
// 请求失败时调用此函数。
error:function(XMLHttpRequest,textStatus,errorThrown){
$("#Loading").empty();
},
error: function () {
alert("error");
}
});
});
});
</script>
</head>
<body>
<div id="Loading"></div>
<input type=button id="button1" value="ajax">
<ul>
<li id="all"></li>
</ul>
</body>
</html>
[/code]