I'm not entirely clear what your callback function or page.ready function
does, but this is how I do it. I have an ajax callback function that
returns a script that clears the timer.
def clear_timer(timer_id):
"""pseudo-code"""
return """<script>
if (...check timer_id valid ...) clear_timer(timer_id)
</script>"""
and this is executed by an ajax(url,['whatever'],':eval'), and the above
script is targeted at a specific hidden div somewhere.
On Sunday, April 8, 2012 4:27:56 AM UTC+8, backseat wrote:
>
> I'm using clienttools.py to put a timer on a page; the timer calls a
> controller function (imaginatively called 'tick') every second, which in
> turn updates a div on the page via Ajax. So far, so good.
>
> I want the 'tick' controller function to be able to stop/disable the timer
> under certain circumstances. I can do this interactively from a link that
> results in the whole page being refreshed, but not from the tick function;
> I think that's because the clienttools page.ready() function is only called
> on initial page load, not from when an Ajax update completes.
>
> Bits of code: to set up the timer:
>
> callback = js.call_function(tick)
> page.ready(js.timer(callback,1000))
>
> ...which works. Calling this from 'tick':
>
> page.ready(js.stop_timer(request.var.timer_id))
>
> ...doesn't stop the timer (the request.vars.timer_id is valid).
>
> Is there a way of stopping the js timer from an Ajax call? Alternatively,
> is there a better way of calling 'tick' to update a page every second?
> --
> "You can have everything in life you want if you help enough other people
> get what they want" - Zig Ziglar.
>
> Who did you help today?
>
>