$(document).ready(function() { // initiatie variables var track_click = 0; var total_pages = 1; // load initial results $('#results').load('../include/clients.php', { 'page': track_click, 'limit': 20, 'total': 9}, function() {track_click++;} ); // button clicked $('.load-more').click(function (e) { // hide load more button on click $(this).hide(); // show loading image $('.loader').show(); // click is less than pages if(track_click <= total_pages) { // post page number and load results $.post('../include/clients.php',{'page': track_click, 'limit':20, 'total':9}, function(data) { // display load more button $('.load-more').show(); // append data $('#results').append(data); // hide loading image $('.loader').hide(); // update click track_click++; // error }).fail(function(xhr, ajaxOptions, thrownError) { // alert with HTTP error alert(thrownError); // bring back load more button $('.load-more').show(); // hide loading image once data is received $('.loader').hide(); }); // compare user click with page number if(track_click >= total_pages-1) { // disable load button $('.load-more').attr('class', 'disabled'); } } }); });