# Recursive ajax call

**URL:** <https://www.ruby-forum.com/t/recursive-ajax-call/115348>\
**Category:** Rails\
**Created:** [September 24, 2007, 9:26am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348 "2007-09-24T09:26:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [September 24, 2007, 9:26am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348/1 "2007-09-24T09:26:59Z")

</div>

Hi,  
Is there any rails ajax tag or possibly any option with the existing  
ones , to set the recursive ajax calls.

For e.g. If I wish to automatically send the next ajax request only  
when the response from the first one is received.

I can do this by setting the call to the same function in  
the :complete=\>‘recursive\_func’, however the ajax tags such as  
periodically\_call\_remote or link\_to\_remote etc don’t let us specify  
any name for the corresponding javascript function.

Any ideas, suggestion on how to implement this.

TIA  
~Shishir

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [September 25, 2007, 8:59am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348/2 "2007-09-25T08:59:25Z")

</div>

I has a similar situation, you’ll need to create “manual” js code:

this is sample, you can easily replace onComplete / onLoading code  
with your own js functions, like onComplete: ajaxQuery(params)  
…

On Sep 24, 9:26 am, Shishir Srivastava [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [September 25, 2007, 9:04am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348/3 "2007-09-25T09:04:26Z")

</div>

Yes i forgot .,.

first make regular ajax “button” …  
that will launch “recursive” function i described above.  
\<%= link\_to\_remote … :complete =\> “ajaxQuery();” … %\>

-donation to Yulia-  
[http://www.yulia-site.org](http://www.yulia-site.org)

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [September 25, 2007, 9:13am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348/4 "2007-09-25T09:13:27Z")

</div>

i forgot …

offcourse you need link\_to\_remote with :completed that will call  
ajaxQuery 🙂

-donations-  
[http://www.yulia-site.org](http://www.yulia-site.org)

---

<div class="post-metadata">

**Author:** ![shishir\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shishir\_s](https://www.ruby-forum.com/u/shishir_s)\
**Post date:** [September 25, 2007, 9:17am UTC](https://www.ruby-forum.com/t/recursive-ajax-call/115348/5 "2007-09-25T09:17:27Z")

</div>

Thanks Alexey. However, I did this using a combination of some of the  
options which periodically\_Call\_remote provides. I implemented it like  
this

\<%= periodically\_call\_remote :update =\> ‘’,  
:condition =\> “document.getElementById("hidden  
").innerHTML==‘false’”,  
:url =\> {:action =\> “msg\_handler”},  
:frequency =\> 2.0,  
:after =\> “hold(true)”,  
:complete =\>“hold(false)” %\>

\<%=  
function hold(value) {  
document.getElementById("hidden").innerHTML=value  
}"

)  
%\>

Basically I am toggling between the values of an element ‘hidden’ to  
automatically send ajax request only when the response has been  
received from the first one. And it works… 😉

~Shishir

On Sep 25, 12:02 pm, “alexey.Creopolis” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
