[Catalyst] implementing ajax
Chisel Wright
chisel at herlpacker.co.uk
Tue Mar 11 22:07:49 GMT 2008
On Tue, Mar 11, 2008 at 02:27:47PM -0700, Jennifer Ahn wrote:
> Hi Ali
>
> Thanks for your suggestions. I was a little reluctant to explor JSON
> because I didn't find the cpan documentation or catalyst book being
> sufficient. Being that this application is my first with catalyst, I wanted
> to tackle one thing at time. Catalyst first, then all the plug in modules.
> If you could provide a working example of hos to implement the js and
> catalyst controller part of JSON, I would greatly appreciate it!
Now that the JSON cat has been let out of the ajax bag, I feel that I
can contribute with how I "do ajax".
I use the YUI toolkit - it just takes away most of the pain. I use the
asyncRequest() method, which is pretty much just a way to get stuff from
the javascript to the server, and deal with the/any response.
The request is just a POST at the end of the day, which I parse the same
as any Catalyst action with params.
I then "use JSON;" [someone will probably suggest JSON::Any] to turn a
perl data structure into a JSON string:
# return some JSON
$json = to_json($return_data);
$c->response->body( $json );
$c->log->info( $json );
return;
For me JSON is easy, painless and does everything I need it to.
Also, for me if XML is the answer, I try to ask different questions
until it goes away.
--
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/
This is not an automated signature.
I type this in to the bottom of every message.
More information about the Catalyst
mailing list