• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling

 
DirenDd Dantanarayana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using this Java Script functions to create a JSP page with Infinite Scroll feature.


----------
As you can see
I'm calling the *loadSubPage* function to append html content in the *'appLeadershipSubView'* page into the *'#mainDiv'*.
And *loadSubPage* is also called at the page Load event also.

The Problem is when i scroll down it makes multiple(2 sometimes 3) calls to the *loadSubPage* function and appends duplicate data into the div.

Since i'm new to JSP and Javascript I couldn't figure out the problem here.
Can you please point me out the problem here?
 
DirenDd Dantanarayana
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add a Boolean to make sure there is not an active request. Check to see if it is active before you make a request.

var isActive = false;
$(window).scroll(function(){
if (!isActive && $(window).scrollTop() == $(document).height() - $(window).height()){
isActive = true;
in the callback, set isActive to false

success: function(html){
$('#mainDiv').append(html);
isActive = false;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic