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
On 29.11.2005, at 20.54, Jason Lee wrote:> 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''.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 -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 On Nov 29, 2005, at 11:41 AM, Jarkko Laine wrote:> > On 29.11.2005, at 20.54, Jason Lee wrote: > >> 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''. > > 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 > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
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 Jason Lee wrote:> 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 >