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: "mainPage.aspx/GetImages",
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);
}
});
}
}
When I add a toolbar to my browser (below of address bar) scroll method doesn't work any more. How can I solve this problem?
I think the condition in if statement is never satisfied in your code. Try to console log out something first to check if scroll is working or not.
HI here is working example. Wrap in document ready function. if still not bubble. let me know what jquery version currently you using.This working example i am using jquery v1.2.3 in that example.
$('div').scroll(function(){ alert("scroling"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div style="overflow: scroll;height:150px;"> aalskdjflkasjdflkasd a'lsdkfjlasjdf;la lkajsdflkjas;df <br> <br>ksdkf;kasd;lfk;asdkf;lasd <br> a;sdjflkasjdflkasd <br> asdf;lkasd;lfasd <br> a;sdjflasjdflkjaskdl <br>asdjflkajsdflkjasdlkf <br> asdfkjlaksdjflkjasdlkf asdljflkasdjflkas<br> alsdkfjlkasdjflasd <br>kaljdsflkjasdlkfjasdl <br> </div>
Note:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.