0
我想使用ajax回調函數自動加載,但GetData
函數在第一次使用相同參數後仍然保持調用狀態。下面是我的javascript代碼:首次調用後始終調用的Ajax回調函數
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
功能。你有建議嗎?