Complex Javascipt Stopped Working after AJAX Call

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

render :update do |page|
page.replace_html ‘ajaxContent’, :partial => “profile”

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”:


And that worked both before and after the AJAX update.

What may be the issue here? Thanks.

Patiently waiting for the gurus :slight_smile:

Alat Meth wrote:

Patiently waiting for the gurus :slight_smile:

That’s how this shop works.

While you wait, you could run in Firefox with Firebug installed. The FAQ
Ajax stopped working” has the first answer “A browser will often decline
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
have a false trail!

Redirecting... ← NOT a blog!!!

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 JS libraries.

Redirecting... ← NOT a blog!!!

Still waiting for guru :slight_smile:

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

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.


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?

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()”


Hey thanks Brian. Any other suggestions?