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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:17:30+00:00 2026-06-10T14:17:30+00:00

I have made a jQuery script that loads items from the database when the

  • 0

I have made a jQuery script that loads items from the database when the user scrolls. Only problem is that when a user scrolls very quickly after page load the result of the script doubles up so the information from the database is shown twice. Not really sure what’s going on here but the script is below. It’s all on doc ready by the way.

function last_item_funtion() 
     { 
     var ID=$(".newsItem:last").attr("id");
     $('#feedLoader').html('<img src="../files/images/bigLoader.gif" style="display:block;margin-left:auto;margin-right:auto;">');
     $.post("AJAX/scroll_feed.php?action=get&last_item_id="+ID,

     function(data){
     if (data != "") {
     $(".newsItem:last").after(data); 
     }
     $('#feedLoader').empty();
     });
     }; 

     $(window).scroll(function(){
     if ($(window).scrollTop() == $(document).height() - $(window).height()){
     last_item_funtion();
     }
     }); 

This isn’t my jsfiddle but it shows in a nutshell what the script does. It doesn’t show the problem I am having but i cannot replicate that as I can’t put a whole database on jsfiddle.

UPDATE
After having a play I have realized that it’s not when the user scrolls straight after page load it’s when the user does one continuous scroll instead of a short one. From this I am guessing that jQuery does not register the data has been loaded until the scroll is stopped.

  • 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-10T14:17:31+00:00Added an answer on June 10, 2026 at 2:17 pm

    Well, I guess the scroll event is fired multiple times, so the request is done multiple times. Try the following:

    function bind_scroll() {
        $(window).bind('scroll', function () {
            if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                $(window).unbind('scroll');
                last_item_funtion();
            }
        });
    }
    
    function last_item_funtion() {
        var ID = $(".newsItem:last").attr("id");
        $('#feedLoader').html('<img src="../files/images/bigLoader.gif" style="display:block;margin-left:auto;margin-right:auto;">');
        $.post("AJAX/scroll_feed.php?action=get&last_item_id=" + ID,
    
        function (data) {
            if (data != "") {
                $(".newsItem:last").after(data);
            }
            $('#feedLoader').empty();
            bind_scroll();
        });
    };
    
    bind_scroll();
    

    It binds the scroll event, and unbinds it after it is triggered. The event is bound again after the request is finished.

    (You might also check out jQuery.one(), but I have never used it.)

    EDIT:
    After doing some testing, the scroll event gets triggered a lot even though we unbind it, so here is an updated example that uses a global variable to tell the scroll-callback if it’s loading something already, or if it’s ok to do a new post request:

    window.scroll_loading = false;
    
    function last_item_funtion() {
        var ID = $(".newsItem:last").attr("id");
        $('#feedLoader').html('<img src="../files/images/bigLoader.gif" style="display:block;margin-left:auto;margin-right:auto;">');
    
        $.post("AJAX/scroll_feed.php?action=get&last_item_id=" + ID,
            function (data) {
                window.scroll_loading = false;
                if (data != "") {
                    $(".newsItem:last").after(data);
                }
                $('#feedLoader').empty();
            }
        );
    };
    
    $(window).bind('scroll', function () {
        if (window.scroll_loading == true) {
            return;
        }
        if ($(window).scrollTop() > $(document).height() - $(window).height() - 10) {
            window.scroll_loading = true;
            console.log("FIRE!");
            last_item_funtion();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a jQuery UI Datepicker script as below to select only Weekends.
I have a pinterest style site and made a jquery script that spaces the
I have made a jQuery toggle for a menu that I had in mind.
Using jQuery UI's Droppable I have made a shelf type thing where the items
I have started using jQuery and rails. I have made a simple form that
I have made a simple chat script using jquery and AJAX but the huge
I have a Google Instant style jQuery search script that queries a PHP file
I have made a jQuery/javascript that is loading a page into a div when
I am writing a script in JQUery that when you select an option from
I have made a user control that allows an image to be uploaded and

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.