var page=1; /*延期加载专用*/
var status=false; /*冲突加载专用*/
function loadMore(url,total){
if(status){
return false;
}
setTimeout(function(){
page++; /*分页专用*/
$.ajax({
//提交数据的类型 POST GET
type:"POST",
//提交的网址
url:url,
//提交的数据
data:"json=home&page="+page,
//返回数据的格式
datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
//在请求之前调用的函数
beforeSend:function(){
status=true;
$("#loading").show().html('加载中,请稍候');
},
//成功返回之后调用的函数
success:function(result){
/*console.info(result);*/
status=false;
$("#loading").hide();
$.each(result, function(key,value){
});
if(total>result.length){
$("#loading").show().html('没了,还加载啥');
status=true;
}
},
//调用出错执行的函数
error: function(){
status=true;
$("#loading").show().html('网络异常');
}
});
}, 500);
}
$(function(){
$(window).scroll(function() {
//当内容滚动到底部时加载新的内容
if ($(this).scrollTop() + $(window).height() + 30 >= $(document).height() && $(this).scrollTop() > 30) {
//当前要加载的页码
loadMore(url,20);
}
});
});

ali
- 发布:2017-04-12 11:51
- 更新:2017-04-12 11:51
- 阅读:2500
更多加载AJAX方法
分类:HTML5+
0 个评论
要回复文章请先登录或注册