Forum: Ruby on Rails Using Ajax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9a5c497293dffb91cacef202bad5b602?d=identicon&s=25 jasonlee9 (Guest)
on 2005-11-29 19:56
(Received via mailing list)
I just got pagination to work with Ajax ( http://wiki.rubyonrails.com/
rails/pages/How+to+Paginate+With+Ajax ) and I'm pretty happy with it.
However, I have a few observations.

With my production app I am/was using the iframe approach to swapping
out div sections. In AWDR it says that XMLHttpRequest is preferred
over this method for various reasons. However, until I read that and
implemented it, I always thought that Rails Ajax apps didn't
necessarily swap out fragments but instead just inserted/updated the
relevant pieces of a div via XML returned from Ajax. The fact that it
is swapping fragments is still nice, but kinda bums me out a bit as I
was hoping for something more 'sexy'.

That said, the Rails Ajax impl is *much* more robust and cleaner than
what I had been using before with iframe plus it's integrated very
nicely. I know too that you can manipulate the DOM tree w/a Ajax
response but I don't think I'm there yet.

Question is, do people prefer to just swap out the fragments or use
the DOM XML update approach? Would be interesting to find out how
many people prefer what and how long development time to do that is.

- jason
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2005-11-29 20:44
(Received via mailing list)
On 29.11.2005, at 20.54, Jason Lee wrote:

> The fact that it is swapping fragments is still nice, but kinda
> bums me out a bit as I was hoping for something more 'sexy'.

Sorry, but I don't really get your point here. AJAX in Rails can do
just the same as AJAX in general. The helpers can insert an item in a
list, a row in a table, update a whole div, you name it. You can
return whatever you want to by the AJAX'ed action and use the
response in every way imaginable. You can even dig your nose with it.
So I can't for the life of me imagine anything more sexy. OK, I can,
but it's got nothing to do with webapps...

//jarkko
9a5c497293dffb91cacef202bad5b602?d=identicon&s=25 jasonlee9 (Guest)
on 2005-11-29 21:08
(Received via mailing list)
I guess I'm not explaining myself very well. So lemmie rephrase my
question, with generalizations, of course. It's obviously quicker
from a newbie development standpoint (isn't it?) to let Ajax swap a
div out with a fragment vs. updating something really specific, like
rows in a table. That being said, does anyone have a preference to
swap out fragments vs. just replacing the table?

For instance, I have a list of news items, 10 to a page out of 6000+.
I'm using Ajax pagination, which just swaps out the fragment and, of
course, this fragment contains all kinds of html markup, usually more
text than the results themselves. But I wonder if it's faster for
Rails to just render XML and then let Ajax then re-fill the table
with the next 10 results. Of course, I then have to also change any
other elements on the page like what window in the results I'm at
(you know, ala 'Displaying 30-40 out of 6000') and including the
pagination links.

Does this make more sense? I'm just soliciting others pros/cons and
experiences with doing this. Thx.

- jason
5c4ff5fdd4cae59a6aa4b516846ca5da?d=identicon&s=25 ncdram (Guest)
on 2005-11-30 16:58
(Received via mailing list)
Hey Jason,

As always, the answer is - IT DEPENDS.

For instance some things I could think of are:

1) If the markup being transferred is high then you could probably use a
rxml template instead of a rhtml template to produce xml and update a
hidden div/iframe using a xmlhttp call. On success of that call you
could use plain old js to update specific portions of your page. Again,
in this case you will have to consider 2 things: a) make sure you don;t
use too much js xml voodoo so that your browser does not seem to be hung
to the user and b) make sure you can do the voodoo in the first place.

2) Or just do what you are doing now - i.e. just replace the whole
table/fragment.

--
Deepak
This topic is locked and can not be replied to.