# Re-running js after ajax call

**URL:** <https://www.ruby-forum.com/t/re-running-js-after-ajax-call/118887>\
**Category:** Rails\
**Created:** [November 1, 2007, 12:46am UTC](https://www.ruby-forum.com/t/re-running-js-after-ajax-call/118887 "2007-11-01T00:46:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 1, 2007, 12:46am UTC](https://www.ruby-forum.com/t/re-running-js-after-ajax-call/118887/1 "2007-11-01T00:46:59Z")

</div>

Ok, so say you have a page, and when it loads, it runs everything in  
application.js.

Here, there is some code in between:  
Event.observe(window, ‘load’, function(){

// Code goes here.

})

Does anyone know, how you could get the same code to run, after  
responding to certain ajax calls?

For example, someone clicks on one of the link\_to\_remote links on the  
page, a call is made, and the js code in application.js is run again.

Is this possible?

---

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 1, 2007, 2:34am UTC](https://www.ruby-forum.com/t/re-running-js-after-ajax-call/118887/2 "2007-11-01T02:34:27Z")

</div>

On 31 Oct 2007, at 23:45, Matthew Swasey wrote:

> Does anyone know, how you could get the same code to run, after  
> responding to certain ajax calls?
> 
> For example, someone clicks on one of the link\_to\_remote links on the  
> page, a call is made, and the js code in application.js is run again.

Well you’ve got a bunch of callbacks with link\_to\_remote  
(:complete, ;success, :failure etc…) Will those do?

Fred

---

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 1, 2007, 3:27am UTC](https://www.ruby-forum.com/t/re-running-js-after-ajax-call/118887/3 "2007-11-01T03:27:03Z")

</div>

That’s exactly what I needed! _Smacks head_

Thank you.
