This retrieves a whole page (some_url) and puts it in #products new Ajax.Updater(''products'', ''/some_url'', { method:''get'' }); Is there a way to retrieve a specific div on that page instead of getting the whole page? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Monday 22 January 2007 00:57, anathema wrote:> This retrieves a whole page (some_url) and puts it in #products > > new Ajax.Updater(''products'', ''/some_url'', { method:''get'' }); > > Is there a way to retrieve a specific div on that page instead of > getting the whole page?Not using the Ajax.Updater - you could cook something up on top of Ajax.Request - if the data returned from the URL is XHTML, you could read it with responseXML, use XPath to extract the chunk(s) of content and assign them to different on-screen elements. All of which is a bit involved... I''m not sure what problem you''re trying to solve, but the Rico.AjaxEngine may be a decent fit - it lets you construct responses composed of multiple chunks of content and/or data, and then extracts and forwards them to registered DOM elements and/or JS objects when the response comes in. Rico''s built on top of Prototype, so should be broadly familiar. Docs here... http://openrico.org/docs/RicoAjaxEngine.pdf (found via Google - I don''t see much mention of AjaxEngine on the Rico site, looking just now. but it''s still in the code for the latest download.) FWIW my own experience of using the AjaxEngine is that it''s rather verbose to set up - URLs, recipient DOM nodes, etc. all need to be explicitly registered - but once it''s set up, it''s pretty useful. Dave -- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous Quickly http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> > On Monday 22 January 2007 00:57, anathema wrote: >> This retrieves a whole page (some_url) and puts it in #products >> >> new Ajax.Updater(''products'', ''/some_url'', { method:''get'' }); >> >> Is there a way to retrieve a specific div on that page instead of >> getting the whole page? > > Not using the Ajax.Updater - you could cook something up on top of > Ajax.Request - if the data returned from the URL is XHTML, you > could read it > with responseXML, use XPath to extract the chunk(s) of content and > assign > them to different on-screen elements. All of which is a bit > involved...sounds beyond my noobness.> > I''m not sure what problem you''re trying to solve,nothing specific really. just playing with, and getting to know what prototype can do. i am honestly surprised that receiving the contents of a specific div, instead of a whole page isn''t built into prototype. Here is a situation I would use it in, and I would think this would be common... Let''s say the user is presented with a link. When the user clicks on the link we want to update a div with with the content of the page that the link points to. but we obviously do not want to update it with a whole page containing navigation and other elements. we just want to give them the content. I could just put the content in generic html file that does not have a doc type, or meta info, or navigation - just a block of content. But if i did that, users who have javascript turned off will not see a fully functional page. That last bit is the major motivation for wanting to be able to fetch a specific div instead of the whole page. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Jan-22 12:21 UTC
Re: Retrieving a specific div or class with Updater
Hey there, anathema a écrit :> This retrieves a whole page (some_url) and puts it in #products > > new Ajax.Updater(''products'', ''/some_url'', { method:''get'' }); > > Is there a way to retrieve a specific div on that page instead of > getting the whole page?OK, so essentially, you''re willing to transmit a whole freakin page over the wire, then hack through its XHTML/DOM, when you really should have a server action that renders the exact content you need, right? This is what partials are for. You should request on a URL whose job it is to render exactly what you need, nothing more. This is very easy on Rails, with RJS templates (or failing that, with partials), and this can also be done in other backends by properly modularizing your view layer (using stuff like Tiles, portlets, or run-of-the-mill includes). -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Monday 22 January 2007 11:51, Shannon wrote:> sounds beyond my noobness.Fair enough, it isn''t a straightforward approach, as I said.> > I''m not sure what problem you''re trying to solve, > > nothing specific really. just playing with, and getting to know what > prototype can do. i am honestly surprised that receiving the contents > of a specific div, instead of a whole page isn''t built into > prototype. Here is a situation I would use it in, and I would think > this would be common... > > Let''s say the user is presented with a link. When the user clicks on > the link we want to update a div with with the content of the page > that the link points to. but we obviously do not want to update it > with a whole page containing navigation and other elements. we just > want to give them the content. I could just put the content in > generic html file that does not have a doc type, or meta info, or > navigation - just a block of content. But if i did that, users who > have javascript turned off will not see a fully functional page. That > last bit is the major motivation for wanting to be able to fetch a > specific div instead of the whole page. >You''d be better off factoring out the part of the page that you want to consume on the server. It''s unusual for an ajax app to make requests to URLs that serve complete HTML pages. Usually, you''d write specific URLs for the ajax calls that contain only fragments of HTML content, or even data encoded as JSON or XML, or whatever. HTH Dave -- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous Quickly http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
>> This retrieves a whole page (some_url) and puts it in #products >> >> new Ajax.Updater(''products'', ''/some_url'', { method:''get'' }); >> >> Is there a way to retrieve a specific div on that page instead of >> getting the whole page? > > OK, so essentially, you''re willing to transmit a whole freakin page > over > the wire, then hack through its XHTML/DOM, when you really should > have a > server action that renders the exact content you need, right?You would be correct if I was building large content heavy site, but the scenario I had in mind would probably be for a small, other was static site.> > This is what partials are for. You should request on a URL whose > job it > is to render exactly what you need, nothing more. This is very > easy on > Rails, with RJS templates (or failing that, with partials), and > this can > also be done in other backends by properly modularizing your view > layer > (using stuff like Tiles, portlets, or run-of-the-mill includes).Again, I see your point if I was building a web app with rails, but I am simply trying to add some functionality to a small site. I could use php includes, but sometimes that would even be too much. Imagine this scenario. Let''s say i want to link to a particular answer on a faq page. the answer is in it''s own container with a named anchor. even if that faq page was using a php include for the content, it would most likely be all the questions and answers, and not an include for each question answer. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---