# Timer for AJAX calls in Rails?

**URL:** <https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479>\
**Category:** Rails\
**Created:** [June 22, 2007, 4:18am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479 "2007-06-22T04:18:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [June 22, 2007, 4:18am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/1 "2007-06-22T04:18:18Z")

</div>

Say I want to perform an ajax action every 10 seconds. Is there a timer  
function in the built-in JavaScript libraries that will let me do this?

–  
Chris S.  
removed\_email\_address@domain.invalid  
[http://www.compiledmonkey.com](http://www.compiledmonkey.com)

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [June 22, 2007, 6:44am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/2 "2007-06-22T06:44:16Z")

</div>

Chris S. wrote:

> Say I want to perform an ajax action every 10 seconds. Is there a timer  
> function in the built-in JavaScript libraries that will let me do this?
> 
> –  
> Chris S.  
> removed\_email\_address@domain.invalid  
> [http://www.compiledmonkey.com](http://www.compiledmonkey.com)

Yes there is. Can’t remember it right now, but i’ve used it before…

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [June 22, 2007, 6:45am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/3 "2007-06-22T06:45:49Z")

</div>

Here it is:

periodically\_call\_remote(options = {})

Periodically calls the specified url (options[:url]) every  
options[:frequency] seconds (default is 10). Usually used to update a  
specified div (options[:update]) with the results of the remote call.  
The options for specifying the target with :url and defining callbacks  
is the same as link\_to\_remote.

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [July 6, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/4 "2007-07-06T23:59:46Z")

</div>

How can I prevent the loading of /test/blank in this example?

\<%= periodically\_call\_remote(:url =\> “/test/blank”, :complete  
=\>‘addRow(“something”);return false;’, :frequency =\> 3) %\>

All I want to do here is call the javascript function addRow, however  
I could not figure out how to accomplish this with out  
leveraging :complete

Any idea? I don’t really want to call /test/blank

Thanks in advance

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [June 27, 2007, 5:54am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/5 "2007-06-27T05:54:12Z")

</div>

Chris S. wrote:

> Say I want to perform an ajax action every 10 seconds. Is there a timer  
> function in the built-in JavaScript libraries that will let me do this?

periodically\_call\_remote ?

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [July 7, 2007, 1:38am UTC](https://www.ruby-forum.com/t/timer-for-ajax-calls-in-rails/107479/6 "2007-07-07T01:38:53Z")

</div>

neutek wrote:

> How can I prevent the loading of /test/blank in this example?
> 
> \<%= periodically\_call\_remote(:url =\> “/test/blank”, :complete  
> =\>‘addRow(“something”);return false;’, :frequency =\> 3) %\>
> 
> All I want to do here is call the javascript function addRow, however  
> I could not figure out how to accomplish this with out  
> leveraging :complete
> 
> Any idea? I don’t really want to call /test/blank

I suspect if you leave the :url out, and leverage :complete, your  
browser  
will periodically call raw JavaScript without hitting a server.

I formerly posted that you could right after I discovered it, but I have  
since retired that code, so Google for the topic and my street name if  
you  
get stuck.

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
