var row = 6, page = 1;
var loading = false; //状态标记
$(document.body).infinite().on("infinite", function () {
if (loading) return;
loading = true;
setTimeout(function () {
var srow = row * (page - 1);
var erow = row * page;
loaddata(srow, erow);
loading = false;
}, 1500); //模拟延迟
});
function loaddata(srow, erow) {
var url = "";
var $html = "";
$.ajax({
type: "get",
url: url,
data: { "srow": srow, "erow": erow},
dataType: "json",
success: function (data) {
if (data == "" || data == null) {
$(document.body).destroyInfinite(); //销毁插件。之后再次调用
$("#load").hide();
// $.toast("无记录显示", "text");
} else {
var res = data;
if (res.length == 0 && page == 1) {
$(document.body).destroyInfinite(); //销毁插件。之后再次调用
$("#load").hide();
// $.toast("没有更多数据啦!", "text");
}
else {
if (res.length < row) {
$(document.body).destroyInfinite(); //销毁插件。之后再次调用
$("#load").hide();
}
var nowDate = new Date(getTime().replace(new RegExp(/-/gm), "/"));//解决兼容
for (var i in res) {
$html += '‘;
}
var $list = document.getElementById("list");
$list.innerHTML += $html;
page++;
}
}
},
error: function (msg) {
$.toptip('数据加载出错', 'error');
$("#load").hide();
}
})
}