Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:10:31+00:00 2026-05-25T19:10:31+00:00

I found a nice ajax/jquery infinite scroll plugin ( http://hycus.com/2011/03/15/infinite-scrolling-like-new-twitter-with-php-mysql-jquery/ ) that I was

  • 0

I found a nice ajax/jquery infinite scroll plugin ( http://hycus.com/2011/03/15/infinite-scrolling-like-new-twitter-with-php-mysql-jquery/ ) that I was able to mold well to my content, but I’m having one issue — it only calls the loadmore.php script once. Let me show the code:

In my index.php file:

<script type="text/javascript">
    $(window).scroll(function(){
        if($(window).scrollTop() == $(document).height() - $(window).height()){
            $('div#loadmoreajaxloader').show();
            $.ajax({
                url: "loadmore.php?lastid=" + $(".postitem:last").attr("id"),
                success: function(html){
                    if(html){
                        $("#postswrapper").append(html);
                        $('div#loadmoreajaxloader').hide();
                    }else{
                        $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
                    }
                }
            });
        }
    });
</script>

This section calls my loadmore.php file and sends it the id of the last post. This only works the first time I scroll to the bottom of the page, it loads the entries from loadmore.php but doesn’t call loadmore.php again. My loadmore.php file has the following code:

<?php

include('./includes/config.php');

if($_GET['lastid']){
    $query = 'SELECT * FROM db WHERE id < "'.$_GET['lastid'].'" ORDER BY id DESC LIMIT 0,3';
    $result = mysql_query($query);
    while ($rec = mysql_fetch_object($result)) {

    [SET MY VARS]

    ?>

    [HTML & PHP DISPLAYING MY POST]

    <?php
    }
}

?>

The 3 posts that show up after the first ajax call come up perfectly, exactly the way I want them to show with the correct data. But I can’t get the next 3 posts to show up after the first 3 show up.

So if I have 5 posts by default on my index.php, I scroll to the bottom, ajax calls 3 more posts, they display perfectly, but nothing displays after that even though there are plenty of posts left to display. Where’s my problem, ajax/jquery wizards?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:10:32+00:00Added an answer on May 25, 2026 at 7:10 pm

    Your “if” condition is only satisfied the first time you scroll. So essentially, the event is getting fired, not when you scroll to the bottom of the page, but when you start scrolling. Replace your code with the following:

    <script type="text/javascript">
        var loading = false;
    
        $(window).scroll(function(){
            var h = $('#postswrapper').height();
            var st = $(window).scrollTop();
    
             // the following tests to check if 
             // 1. the scrollTop is at least at 70% of the height of the div, and 
             // 2. another request to the ajax is not already running and 
             // 3. the height of the div is at least 500. 
             // You may have to tweak these values to work for you. 
            if(st >= 0.7*h && !loading && h > 500){
                loading = true;
                $('div#loadmoreajaxloader').show();
                $.ajax({
                    url: "loadmore.php?lastid=" + $(".postitem:last").attr("id"),
                    success: function(html){
                        if(html){
                            $("#postswrapper").append(html);
                            $('div#loadmoreajaxloader').hide();
                        }else{
                            $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
                        }
                        loading = false;
                    }
                });
            }
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a nice little script on snippr( http://snipplr.com/view.php?codeview&id=799 ) that gives me the
I found the very nice demo by Oleg (http://www.ok-soft-gmbh.com/jqGrid/FillToolbarSearchFilter.htm) which shows a jqGrid toolbar
I found a nice solution on this webiste http://www.thesilvermethod.com/Default.aspx?Id=ModalDialogManagerAsimpleapproachtodealingwithmodaldialogsinMVVM But had to do some
I've found nice examples using C++ ( http://www.codeproject.com/KB/tips/resswitch.aspx ), but not in C#. Can
Found a nice drop down menu: Demo: http://www.jqueryload.com/examples/menu/ HTML, CSS & JavaScript: http://www.jqueryload.com/jquery-dropdown-menu-with-google-style I've
I found a nice script to import xml using powershell http://slash4.de/tutorials/Automatic_mediawiki_page_import_powershell_script Currently I don't
Basically I want to replicate the page changing effect found here, at http://timvandamme.com/ But
I have just found a nice look that I would like to use for
I found nice little one example of Scala today. Something like: (1 to 100)
I found this nice memoizing decorator: http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize The particular application is in artificial intelligence,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.