I am trying to make infinite scroll loads data with below script. Initial data loads correctly but seems like no scroll is detected. I've tried adding alert to debug but I can't seem to find the problem. Backend page p_load.php is working fine. Any idea what might be the issue?
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
var loading = false; //to prevents multipal ajax loads
var total_groups = 2; //total record group(s)
$('#result').load("p_load.php?t=", {'group_no':track_load}, function() {track_load++;}); //load first group
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() >= $(document).height()) {
alert("Detected scrolling"); //not working
if(track_load <= total_groups && loading==false) //there's more data to load
{
loading = true; //prevent further ajax loading
$('.animation_image').show(); //show loading image
//load data from the server using a HTTP POST request
$.post('p_load.php?t=',{'group_no': track_load}, function(data){
$("#result").append(data); //append received data into the element
//hide loading image
$('.animation_image').hide(); //hide loading image once data is received
track_load++; //loaded group increment
loading = false;
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$('.animation_image').hide(); //hide loading image
loading = false;
});
}
}
});
});