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 8990569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:31:42+00:00 2026-06-15T22:31:42+00:00

I am trying to use the following function to load an ajax call when

  • 0

I am trying to use the following function to load an ajax call when the user scrolls to the bottom. However, for some reason the function only fires the ajax call when the user scrolls to down and then back to the top. Here is my code:

$(window).scroll(function()
{   
if($(window).scrollTop() == $(document).height() - $(window).height())
{
    $('div#loadmoreajaxloader').show();
    $.ajax({
    url: "loadmore.php",
    success: function(html)
    {
        if(html)
        {
            var el = jQuery(html);
            jQuery(".content").append(el).masonry( 'appended', el, true );
            $('div#loadmoreajaxloader').hide();
        }else
        {
            $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
        }
    }
    });
}
});
  • 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-06-15T22:31:43+00:00Added an answer on June 15, 2026 at 10:31 pm

    Check it like this:

      fetchContent = function() {
        if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
            console.log('At bottom!!');
    
            // Remove the handler temporarily, so no more scroll events will fire.
            $(window).off('scroll', fetchContent);
    
            // Make the AJAX call.
            $('div#loadmoreajaxloader').show();
            $.ajax({
                  url: "loadmore.php",
                  success: function(html)
                  {
                     if(html)
                     {
                         var el = jQuery(html);
                         jQuery(".content").append(el).masonry( 'appended', el, true );
                         $('div#loadmoreajaxloader').hide();
                     }else
                     {
                         $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>');
                     }
                     // Re-attach the handler, so scroll events will fire again
                     $(window).on('scroll', fetchContent);
                  }
                 });
         }
      };
    
      $(function() {
          $(window).on('scroll', fetchContent);
      });
    

    EDIT:

    I’ve done a JSBin which displays a div when user scrolls to the bottom. You can see it here: http://jsbin.com/axobow/2

    I know that’s not exactly what you need, but it should give you an idea. Iv’e also updated the code a little bit to go inline with what you should have as the final product.

    Please check.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the following script in asp.net: <script language=javascript type=text/javascript> function
The following error is returned when trying to use a MySQL function.. #1418 -
I'm trying to use the following code # LOAD XML FILE $XML = new
I'm trying to use the following code to make an image fadeOut and, only
I'am trying to use some values from the upper function in the inner function:
Trying to use this following script to load a page so that I can
I'm trying to use the following code: $('#clicker').click(function(){ var canvasRef = $('<canvas id=project_canvas/>'); var
I'm trying to use the Google to load jQuery for some pages and jQuery
I'm trying to use the following code to load an external page into a
I am trying to use the following javascript code to alert the user when

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.