Created
August 11, 2014 04:53
-
-
Save jokosusilo/b3be380b68a45c350d9f to your computer and use it in GitHub Desktop.
Scroll Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
var track_load = 0; //total loaded record group(s) | |
var loading = false; //to prevents multipal ajax loads | |
var total_groups = 10; //total record group(s) | |
$('#results').load("autoload_process.php", {'group_no':track_load}, function() {track_load++;}); //load first group | |
$(window).scroll(function() { //detect page scroll | |
if($(window).scrollTop() + $(window).height() == $(document).height()) //user scrolled to bottom of the page? | |
{ | |
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('autoload_process.php',{'group_no': track_load}, function(data){ | |
$("#results").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; | |
}); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment