File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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
problem in loading javascript for IE
javascript and jsp forward
invoking servlet on body unLoad( )
jQuery UI tabs not loading in the same tab
onload not working with jsp