samedi 18 avril 2015

Prevent multiple request on scroll

I use this code to get data from server while scrolling using jQuery AJAX:



var pageIndex = 0;
var pageCount;

$(window).scroll(function () {

if (($(window).scrollTop()) == ($(document).height() - $(window).height())) {
GetRecords();
}
});
$(function () {
GetRecords();
});
function GetRecords() {
pageIndex++;
if (pageIndex == 1 || pageIndex <= pageCount) {
$("#loader").show();
$.ajax({
type: "POST",
url: "http://ift.tt/1Q1wtQq",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}
}


But : 1- how can I prevent multiple request to webmethod at a moment? 2- when I add a toolbar to my browser (below of address bar) scroll method doesn't work any more.


Aucun commentaire:

Enregistrer un commentaire