This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
Similar Threads
invoking servlet on body unLoad( )
javascript and jsp forward
onload not working with jsp
jQuery UI tabs not loading in the same tab
problem in loading javascript for IE