实现在移动端下拉ajax加载更多数据功能
var i = 2;//从第二页开始取数据 var n = 1; var loadMore = function(url,id){ var len = $(window).height() + $(window).scrollTop() + 200; var bodylen = $("body").height(); // console.log(len+" "+bodylen) if(len > bodylen){ var addurl = url + i +"/10" // console.log(addurl); if(n){ $.ajax({ url: addurl , type: 'get' , data: {} , dataType: 'json' , success: function(data){ if(data) $(id).append(data); else n = 0; }, error : function(){ console.log("异常") } }); i = i + 1; } } }
HTML调用:
var url = $('#pageAjaxUrl').val();
var tableid = $("#equip-table");
window.onscroll = function(){loadMore(url,tableid);}