我想使用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
函数。你有建议吗?
答案 0 :(得分:0)
问题在于:
if (st > lastScrollTop) {
if (st > window.innerHeight) {
检查出来,因为出于某种原因进入函数的这一部分而不滚动。如果我有时间,我会看看。