# Complex Javascipt Stopped Working after AJAX Call

**URL:** <https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910>\
**Category:** Rails\
**Created:** [January 1, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910 "2007-01-01T21:30:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 1, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/1 "2007-01-01T21:30:49Z")

</div>

This has to be the weirdest problem ever.  
I will be as specific as possible.

Let’s say I have a partial “\_profile.rhtml”.  
It is first displayed in “user.rhtml” using:

\<…\>

 \<%= render :partial=\>'profile' %\>
\<...\>

All javascripts on the “\_profile” partial works (more specifically, a  
lightbox script (ibox) and a sortable table script). However, when the  
profile is updated via an AJAX call, say via someMethod in my user  
controller:

\<…\>  
render :update do |page|  
page.replace\_html ‘ajaxContent’, :partial =\> “profile”  
end  
\<…\>

The partial is read and rendered in the the correct div and everything  
seems working except that all the “complex” javascripts stopped working.  
(i.e. Table no longer sorts and lightbox doesn’t appear) I’ve added a  
line of “simple” javascript to “\_profile.rhtml”:

simple

And that worked both before and after the AJAX update.

What may be the issue here? Thanks.

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 1:31am UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/2 "2007-01-02T01:31:05Z")

</div>

Patiently waiting for the gurus 🙂

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 1:42am UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/3 "2007-01-02T01:42:30Z")

</div>

Alat Meth wrote:

> Patiently waiting for the gurus 🙂

That’s how this shop works.

While you wait, you could run in Firefox with Firebug installed. The FAQ  
“My  
Ajax stopped working” has the first answer “A browser will often decline  
to  
run any Javascript after an error”. So trap the error and you might just  
solve it yourself.

If you do, please remember to finish your own thread, so the archives  
won’t  
have a false trail!

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 1:58am UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/4 "2007-01-02T01:58:34Z")

</div>

> Any other possibilities? Could it be a configuration problem?

Try the Rails-spinoffs mailing list (stupid name, I know) for the  
interaction between Rails and the [Script.aculo.us](http://Script.aculo.us) JS libraries.

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 12:42pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/5 "2007-01-02T12:42:18Z")

</div>

Still waiting for guru 🙂

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/6 "2007-01-02T17:10:08Z")

</div>

I’m no guru, but I had a similar problem once so maybe my experience  
will be helpful.

This was a while back, and I’m barely awake yet, so forgive my  
vagueness.

In my situation, the JS in the partial was setting up some structures,  
lets say a sortable list, but there was a single line of javascript at  
the end of the page which “turned on” all the objects. When reloading a  
partial, all the setup code got re-done, but the code outside the  
partial was of course not re-loaded, so the objects remained inert.

HTH,  
Brian

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 1:53am UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/7 "2007-01-02T01:53:32Z")

</div>

Thanks Phlip, I’ve followed your advice but firebug has detected no JS  
errors. Meanwhile, I’ve also commented out most of the stuff that is not  
relavant but it seems that javascript just refuse to function after been  
called via AJAX. (The AJAX update itself is working fine)

Any other possibilities? Could it be a configuration problem?

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/8 "2007-01-02T19:09:38Z")

</div>

Alat Meth wrote:

> Hey thanks Brian. Any other suggestions?

Thanks Brian, it worked like a charm.

For future reference, most JS libraries call to init itself by:  
Event.observe(window, ‘load’, SortableTable.load);

But after an AJAX call, you might have to reload it manually, add this  
to the link\_to\_remote or observe\_field etc.  
:complete =\> “SortableTable.load()”

Thanks.

---

<div class="post-metadata">

**Author:** ![alatmeth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@alatmeth](https://www.ruby-forum.com/u/alatmeth)\
**Post date:** [January 2, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/complex-javascipt-stopped-working-after-ajax-call/80910/9 "2007-01-02T18:33:46Z")

</div>

Hey thanks Brian. Any other suggestions?
