Strategies for updating multiple parts of the page with AJAX


#1

Hi all,

I have a layout that’s evolving, but it looks like there will be several
divs. I’m trying to keep everything AJAX-y and avoid full page reloads.
My
problem is, if I have the login box in a div, I’m going to want two
other
divs to effectively “refresh” themselves to get data from the server now
that there is a user logged in.

I’m trying to figure out how to accomplish this. I know I can’t do this
with my current layout, because each of these divs I want to refresh is
currently just a partial page template included on a page - nothing
AJAXy
about them. If I want to have the ability to call on parts of the page
to
update themselves, any ideas how I can do that? I’m not sure if there
are
rails helpers I can use, or if I should start looking into hand-coding
Javascript with the prototype library to come up with a way.

Also, if my mental model of how to do page updates is wrong, please
correct
me.

Thanks!
Tom


#2

Tom L. wrote:

Hi all,

I have a layout that’s evolving, but it looks like there will be several
divs. I’m trying to keep everything AJAX-y and avoid full page reloads.
My
problem is, if I have the login box in a div, I’m going to want two
other
divs to effectively “refresh” themselves to get data from the server now
that there is a user logged in.

Sounds like you might like RJS templates. They are in edge rails but I
think there is a plugin for rails 1.0.

Alternatively, you could add some javascript to the :complete callback
in link_to_remote that will fire off another request.

link_to_remote ‘link’, :update=>‘testdiv’, :url=>{:action=>‘action’},
:complete=> remote_function(:update=>‘testdiv2’,
:url=>{:action=>‘action2’})

should do the trick.

_Kevin


#3

just take a look at RJS (at rails edge), this is the easiest way for
multiple partial AJAX page reloads without handcoded javascript