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

  • SEARCH
  • Home
  • 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 8112117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:22:10+00:00 2026-06-06T02:22:10+00:00

Hi guys I have my endless page js code working great but for some

  • 0

Hi guys I have my endless page js code working great but for some reason it only triggers for the second page. I did some changes to some code I found around to meet my needs but now instead of keep loading items it stops in page 2 as my console logs state. Here is my code, can someone please check it and tell me why this isn’t triggering? As for my pagination I am using will_paginate gem and I get the links to the pages on the bottom so the back es is working fine. Thank you in advance.

EDIT 2: If someone ever runs into my problem, here is my final setup.

- content_for :scripts do
  :javascript
    (function() {
      var divContainer = $('#posts-container');
      var page = 1,
          loading = false;
      var current_url = divContainer.data('url') + '?page=';

      function nearBottomOfPage() {
        return $(window).scrollTop() >= $(document).height() - $(window).height() - 10;
      }

      $(window).scroll(function(){
        if (loading) {
          return;
        }

        if(nearBottomOfPage()) {
          loading=true;
          page++;
          $.ajax({
            url: current_url + page,
            type: 'get',
            dataType: 'script',
            success: function(html) {
              var $items = $(html).find('.item');
              jQuery(".content").append($items).masonry( 'appended', $items, true );
              $(".content").masonry('reload');
            },
            error: function() {
              console.log("Error")
            },
            complete: function() {
              loading = false;
            }
          });
        }
      });
    }());

EDIT 1:

I found that the nearBottomOfPage() function is not working properly. It only triggers the first time and it never returns true again. Why can this be?

  • 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-06T02:22:11+00:00Added an answer on June 6, 2026 at 2:22 am

    One thing I notice is that you set your “is loading” flag to true:

    if(nearBottomOfPage()) {
      loading=true;
    

    but you never set it back to false. That means that your nearBottomOfPage() check will only be triggered once.

    Try updating your AJAX success handler to reset loading:

    success: function(html) {
      var $items = $(html).find('.item');
      $(".content").append($items).masonry( 'appended', $items, true );
      $(".content").masonry('reload');
      console.log("Reloaded masonry");
      loading = false; // <----------------------------- This is sort of important.
    }
    

    You might want to add an error handler to your AJAX as well. Then you could move the loading = false; to a complete callback:

    success: function(html) {
      // As you have it now...
    },
    error: function() {
      // Complain or something...
    },
    complete: function() {
      loading = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python list comprehensions are nice, but near impossible to debug. You guys have any
guys I have two question to ask, they're easy, but bothering me for a
Guys i have a WebView in my Screen with some TextFields in it. Whenever
hi guys i have two pipe delimited files,first file contains 1000 records and second
Hi guys I have an easy question, but not easy to me. I have
I don't know if this is the correct website, but you guys have been
Hey guys have her an code where i add an option to a html
Do you guys have some tips to make any large table, with 500+ rows,
Do you guys have some .Net libraries which has ability to convert a PowerPoint
Guys, I have some input checkbox tags: They look pretty light and hard to

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.