Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do You Terminate a Javascript Process

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
Hello,

I am using the following code to provide endless scrolling of content on my website. The code works fine and I have no problems with any of it with the exception of one minor thing. When I have no more results to display, the endless scrolling Javascript continues to activate and tries to load more results when the browser's scroll bar touches the bottom. Does anyone know how I can simply just terminate the javascript endless scrolling script once my classic ASP determines that there are no more results to load? I am guessing there is some sort of a "terminate all scripts" function or javascript routine I can use to just stop the infinite scrolling from executing in the current session?

Thanks for any help.



Code:
<html>
<head>
<style>
.wrdLatest {
position: relative;
display:block;
}

}
#lastPostsLoader {
text-align: right;
	width: 20px;
	margin: 125px auto 0 auto;

	
}

.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, -50%);
}
</style>
<script type="text/javascript" src="/scroll/jquery-1.2.6.pack.js"></script>
<SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">

//Start Endless Scroll Script	
	
		$(document).ready(function(){
		
		$('form#mainForm').bind('submit', function(e){
			e.preventDefault();
			checkForm();
		});
		
		$('input#hostName').focus();
	


//Loading More content			
		function lastPostFunc() 
		{ 
			$('div#lastPostsLoader').html('<img class="centered" src="/scroll/rolling.gif">');
			$.post("/?thesearch=<%=thesearch%>&location=<%=location%>&action=getLastPosts&start="+$(".wrdLatest:last").attr("id"),
	
			function(data){
				if (data != "") {
				$(".wrdLatest:last").after(data);			
				}
				$('div#lastPostsLoader').empty();
			});
		};  
		
		
//Scroll Detection		
		$(window).scroll(function(){
			if  ($(window).scrollTop() == $(document).height() - $(window).height()){
			   lastPostFunc();
			}
		}); 
		
	});

</script>
</head>
<body>
' *** Very first set of results to be loaded and displayed:
<% If action <> getLastPosts Then %>
      <span>[i]First Page of content. Enough content would be loaded in this area to where the user would have to scroll to see more [/i]</span>
      <% start = start + 25 %>
      <div class="wrdLatest" id="<%=start%>">
      <div id="lastPostsLoader"></div>
<% Else
   ' **** This is where more content would get added to the bottom of the previous page if the user's scrollbar touches the bottom  %>
       <span>[i]Enough content would be loaded in this area to where the user would have to scroll down to see more content. [/i]</span>
       <span>[i]If there isn't a lot of content here, then we want to simply just end the infinite scroll javascript and prevent it from executing if the user's scroll bar touches the bottom.[/i]</span>
       <% start = start + 25 %>
      <div class="wrdLatest" id="<%=start%>"></div>
<% End If %>

</body>
</html>
 
endless scrolling script once my classic ASP determines that there are no more results to load?

You can't, ASP scripts have completed and exited long before javascript even runs.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Chris,

That is not my question. I am looking for a way to prevent SUBSEQUENT javascript from executing. This infinite scrolling actually uses Jquery. Jquery has a .stop() method. I just don't know how to properly use it for what I need.
 
basically javascript stops when it runs out of things to do.

{quote]That is not my question[/quote]

Are you sure? Because this;
{quote]Does anyone know how I can simply just terminate the javascript endless scrolling script once my classic ASP determines that there are no more results to load?[/quote]
Seems to be exactly what you were asking.

But to exit a javascript loop you use the break statement

I have no idea what a jquery stop() function does simply because I have never needed to use jquery for anything.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top