Jump to content

Getting my ajax to pull the correct page results for lazy loading.


adandy

Recommended Posts

I am trying to implement lazy loading into a project with pagination already set up.


If I was to go to my website and after the .com, type in "api_courselist.php?page=1" I would receive the first 20 results of my query. If I was to change that to page=2, it would retrieve the next 20 and so on.


My issue is I have no idea how to implement that into my java script/ajax file. I have it set up so that when the user scrolls to the bottom of the page, a div will make its self visible with the new page populated inside of it and IT will keep on pulling pages in till There is no more content.



jQuery(function ($) {
jQuery(document).ready(function() {
var is_loaded = true;
jQuery(window).scroll(function() {
if(jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()) {


jQuery('div#loadMore').show();
if(is_loaded){
is_loaded = false;
jQuery.ajax({
url: "api_courselist.php?page=1",
success: function(html) {
is_loaded = true;
if(html){
jQuery("#infiscroll").append(html);
jQuery('div#loadMore').hide();
}else{
jQuery('div#loadMore').replaceWith("<center><h1 style='color:red'>End of Content !!!!!!!</h1></center>");
}
}
});
}
}
});

});
});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.