aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling" Watch "How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling" New topic
Author

How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling

DirenDd Dantanarayana
Greenhorn

Joined: Sep 11, 2011
Posts: 3
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

Joined: Sep 11, 2011
Posts: 3
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;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Avoid Multiple JavaScript Function Calls in Infinite Scrolling