我想使用 ajax 回调函数进行自动加载,但GetData
首先使用相同的参数调用该函数。这是我的javascript代码:
var currentPage = 0;
var isFinished = false;
var lastScrollTop = 0;
$(window).data('ajaxready', true).scroll(function (e) {
if ($(window).data('ajaxready') == false) return;
$(window).scroll(function (event) {
var st = $(this).scrollTop();
if (st > lastScrollTop) {
if (st > window.innerHeight) {
var amountValue = $("#amount").val();
var firstPrice = 0;
var lastPrice = 10000;
InfiniteScroll(firstPrice, lastPrice);
}
}
});
});
function InfiniteScroll(firstPrice, lastPrice) {
if (firstPrice < 0 || firstPrice == undefined) {
firstPrice = 0;
}
if (lastPrice < 0 || lastPrice == undefined) {
lastPrice = 10000;
}
if (isFinished) {
return;
}
$('#divPostsLoader').html('<img src="images/loader.gif">');
var rawPath = window.location.pathname.split('/');
var categoryId = rawPath[rawPath.length - 1];
$("#load").show();
$.ajax({
type: "POST",
url: "http://localhost:60579/AjaxCallPage.aspx/GetData",
data: "{categoryId:" + categoryId +
",page:" + currentPage +
",skip:'9',firstPrice:" + firstPrice + ",lastPrice:" + lastPrice + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.d.length < 3) {
isFinished = true;
}
var products = JSON.parse(data.d);
$.each(JSON.parse(data.d), function () {
// ... do smth..
});
currentPage += 1;
$("#load").hide();
}
});
};
我不向下滚动,但它GetData
在第一次调用后调用函数。你有建议吗?