[Catalyst] AJAX best practices, maximum availability

Ash Berlin ash at cpan.org
Tue Nov 21 01:35:03 GMT 2006


Drew Taylor wrote:
> On 11/20/06, Renaud <renaud at linuxaddicts.com> wrote:
>>
>> I have a site where you can display information about restaurants. You 
>> get
>> those informations with links like /restaurant/1234/menu,
>> /restaurant/1234/access, /restaurant/1234/rates...
>>
>> I'd like to update my page using ajax but without forgetting the clients
>> who cannot support it, so by default, the menu items link to
>> /restaurant/1234/menu, .../access, and so on.
>> If the client supports it, it replaces the links to functions that will
>> instead replace the content of some div where I display the requested
>> information. However to retrieve only the content of that div instead of
>> the whole page, it will fetch /restaurant/1234/menu/content,
>> /restaurant/1234/access/content, and so on...
> 
> Sorry, I know nothing about the chained accessor stuff, but this is
> exactly the sort of thing I've been looking for to help me understand
> WHY I would use chained actions. :-) I got the technical bits, but I
> had not yet seen a proper use case. Now it all makes sense. Thanks!
> 
> Dev folks, I would love to hear you chime in too.
> 
> Drew


Yup. Chains of:

/restaurant/*/menu
/restaurant/*/menu/content

Note. Since a sub cannot be both an endpoint an a chain in a link you 
have to do something like:

sub menu_endpoint : Chained('restaurant') Args(0) { }
sub menu_chain    : Chained('restaurant') CaptureArgs(0) { }
sub menu_content  : Chained('menu_chain') Args(0) { }


The other option for AJAX would be to do something with accept-headers, 
so make the ajax request request a different content type (I forget the 
exact terms) and when not using ajax you process the wrapper/surrounding 
template (i.e. the rest of the page) and then insert the output of what 
would be the ajax command in the correct place.

Not sure if that is more or less hassle than its worth tho ;)

Ash



More information about the Catalyst mailing list