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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:39:21+00:00 2026-05-22T19:39:21+00:00

I have a div, when user scroll to bottom of div, jquery will get

  • 0

I have a div, when user scroll to bottom of div, jquery will get more data from other page and add it to the div. My problem is sometime the scrollbar remain at bottom of div for too long, so it execute jquery statement for multiple times. Jquery get and add duplicated data to the div. How to prevent jquery get and add duplicated data when the scrollbar remain at bottom of div for too long? My codes :

function scrollalert(){
    var elements = $(".messagepiecetime");
    var lastmsgid = elements.eq(elements.length - 1).attr('id');        
    var scrolltop=$('#scrollbox').attr('scrollTop');
    var scrollheight=$('#scrollbox').attr('scrollHeight');
    var windowheight=$('#scrollbox').attr('clientHeight');
    var scrolloffset=20;
    if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
    {   
        $.get('test7a.php?lastmsgID=' + lastmsgid, '', function(newitems){
            $('#content').append(newitems);                             
        }); 
    }
    setTimeout('scrollalert();', 1000);
}

setTimeout('scrollalert();', 1000);// this is where the problem happen. The problem is fixed if I set it to 3000 miliseconds. Output will be 8 duplicated data if I set it to 1 milisecond. I know set 3k miliseconds can fix the problem, but I don’t want users wait for 3 seconds to get new data every they scroll to bottom. Is there any other way to fix it without using setTimeout 3 seconds?

  • 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-22T19:39:22+00:00Added an answer on May 22, 2026 at 7:39 pm

    You could set a global variable that will flag if more data should be loaded.

    var loadMore = true;
    
    function scrollalert() {
        var elements = $(".messagepiecetime");
        var lastmsgid = elements.eq(elements.length - 1).attr('id');
        var scrolltop = $('#scrollbox').attr('scrollTop');
        var scrollheight = $('#scrollbox').attr('scrollHeight');
        var windowheight = $('#scrollbox').attr('clientHeight');
        var scrolloffset = 20;
        if ((scrolltop >= (scrollheight - (windowheight + scrolloffset))) && loadMore) {
            loadMore = false;
            $.get('test7a.php?lastmsgID=' + lastmsgid, '', function(newitems) {
                $('#content').append(newitems);
                loadMore = true;
            });
        }
        setTimeout('scrollalert();', 1000);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a div in the bottom right portion of a page, and
I have a div with is replaced upon certain user actions. These actions are
I have a div element containing some text. When the user clicks a word
I have a div and an iframe on the page the div has z-index:
I have a div in which a page is loaded with the DojoX Layout
I have couple of forms on my php page. I am using jQuery (&
I have a div which is constantly streaming data and has functionality allowing it
I have a div with a scroll bar which displays 15 months with 3
I have a div with defined height, and overflow:scroll; . Its content is too
I have in my page a button which when clicked displays a div (popup

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.