PHP中的滚动加载数据,php+ajax实现拖动滚动条分批加载请求加载数据

无标题文档

varPageNo= 1;varPageSize= 50;

$(document).ready(function(){

$.get("ajax.php",function(data){

$("#mypage").html(data);

})

})

iIntervalId=setInterval("test();",2000);functionshow(){

PageNo++;

pageOffset=(PageNo-1)*PageSize+1;

$.get("ajax.php?act=get_more&LimitStart="+pageOffset+"&PageNo="+PageNo+'&r='+Math.random(),function(data){if('failure' !=data){

$("#mypage").append(data);//$("#showmore").html('显示更多结果');

}

})

}//当前滚动条位置高度

functiongetScrollTop(){varscrollTop=0;if(document.documentElement&&document.documentElement.scrollTop){

scrollTop=document.documentElement.scrollTop;

}else if(document.body)

{

scrollTop=document.body.scrollTop;

}returnscrollTop;

}//取窗口可视范围的高度

functiongetClientHeight(){varclientHeight=0;if(document.body.clientHeight&&document.documentElement.clientHeight)

{varclientHeight=(document.body.clientHeight

}else{varclientHeight=(document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;

}returnclientHeight;

}//显示状态加载图片

functionshowLoadingImg() {

$('#showmore').html('loading.gif显示更多结果');

}//取得当前页面显示所占用的高度

functiongetScrollHeight()

{returnMath.max(document.body.scrollHeight,document.documentElement.scrollHeight);

}functiontest()

{if(getScrollTop()+getClientHeight()==getScrollHeight())

{//此处还要做判断,判断数据是否已经加载完,若加载完就不在显示加载图片

$.get("ajax.php?act=GetPageTotal",function(data){//var string = PageNo + '----' + data;

//alert(string);

if(PageNo>=data){

clearInterval(iIntervalId);

$("#showmore").hide();return;

}

})

showLoadingImg();

show();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值