[Catalyst] Using JSON
Emmanuel Quevillon
tuco at pasteur.fr
Wed Apr 15 06:57:49 GMT 2009
Octavian Râşniţă wrote:
> Hi,
>
> What's the recommended module for getting a JSON request and creating a
> JSON response in a Catalyst app?
> (I want to use them with JQuery.)
>
> Thanks.
>
> Octavian
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
Hi Octavian,
For my part, I use Catalyst::Controller::REST and jQuery. I don't
even use Catalyst::View::JSON to send Json data, as everything (for
what I need) is done by Controller::REST. I force REST to use json
from my config file like :
Controller::REST:
stash_key: rest
default: 'application/json'
Right now I only use REST to delete some entry in my db. For that I
created a Javascript function (using jQuery) that use type 'DELETE'
as method.
Here is an example of my tt2 file :
<a href="#" onclick="remove('[% rest %]');return false;">Remove</a>
Here the JS function called:
function remove(url){
jQuery.ajax(
{
type: "DELETE",
dataType: "json",
url: url,
success: function(data)
{
...
}
And I implemented the corresponding method to
delete/update/create/insert in my Controller::REST
It works like a charm for me.
Hope this will help
Regards
--
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------
More information about the Catalyst
mailing list