[Seaside] Clear/stop a periodic javascript process using Seaside?

Johan Brichau johan at inceptive.be
Tue Feb 1 07:34:46 UTC 2011

You can assign the id that is returned by setInterval() to a global variable and call clearInterval() whenever you want to. 

The best thing to do in this case is use an external javascript file where you declare the (global) variable that should keep the reference id (at least) and also the functions that will register the id and cancel the periodic update. You then call these functions from within the Seaside-generated javascripts. Although you can probably make it work without the external javascript file, it's better practice imho. Here's what I would do:

var updateId;
function registerAndSetInterval(aLambda,ms) {
	updateId = setInterval(aLambda,ms);
function unregisterInterval(){

Next, I'm a bit puzzled with your Seaside code. Doesn't that create a nested div inside the already existing div every 2 seconds? Since the load block creates another div with the same id, you will run into problems. You also need to use the canvas object that is passed to the html load block instead. Here is what I make of it:

renderContentOn: html
	(html div)
		id: 'replace';
		script:  (JSStream on: 'registerAndSetInterval')
					call: '' 
					with: ((html jQuery id:'replace')
								load html: [ :h |
											count := count + 1.
											h render: 'count: ' , count greaseString ]) asFunction
					with: 2000

Calling a javascript function from Seaside-generated javascript is a bit awkward using the #call:with: because it was designed to be sent to a receiver object (such as jQuery instance). But I don't think there's another way to call them from Seaside-generated javascript.

Hope it works, if not: please let me know ;-)


On 31 Jan 2011, at 21:44, Paul DeBruicker wrote:

> Hi -
> Using jQuery/AJAX & Seaside 3.0.3 I'm trying to check for the results of a calculation and when its complete update a div and then stop checking without doing a full page refresh.  I can do everything but stop the periodic process without doing a refresh
> If I have an inst var named 'count' and do this:
> renderContentOn: html
> 	(html div)
> 		id: 'replace';
> 		script:  ((html jQuery id:'replace')
> 					load html: [ :h |
> 						count := count + 1.
> 						(html div)
> 						id: 'replace';
> 						with: [ html render: 'count: ' , count greaseString ] ] ;
> 					interval: 2 seconds).
> every two seconds the count is increased and then displayed.   If I use replaceWith: I have the same problem.  The only thing I know to stop the periodic process is to refresh the page and just render the results I had been waiting on.
> I would like to use AJAX, rather than refresh so I can do this in several places on a single page.
> Its my understanding that the setInterval function has an id that can be sent to clearInterval but I don't know how to get the function id through Seaside.  Is there a way to get that id and send it to clearInterval or another way to do what I want?
> Thanks
> Paul
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

More information about the seaside mailing list