[Catalyst] deserializing key value pairs Catalyst::Controller::REST

J. Shirley jshirley at gmail.com
Fri Jul 25 15:23:21 BST 2008


On Fri, Jul 25, 2008 at 1:48 AM, Jochen Luig <skirnir at gmx.net> wrote:
> Hi Hani,
>
>> var postData = "source_account=1&destination_account=2&ingestor_id=10&source_id=1"
>>
> I think this is where it fails. As far as I can tell from your code,
> postData should contain a JSON Object.
> Try something like:
>
> var postData = '{ "source_account": "1", "destination_account": "2",
> "ingestor_id": "10", "source_id": "1" }';
>
>
> On another note, make sure that YAHOO.util.Connect.asyncRequest doesn't
> mess up your request somehow (is that YUI, btw?). I've just experienced
> the same annoyance with Dojo, whose dojo.xhrPost is not exactly fond of
> sending JSON-Objects. It helps to look at the request itself with some
> tool like e.g. wireshark.
>
> HTH,
>
> Jochen
>
>

Right, Hani is sending url form encoded post body, which is not JSON
and will fail to be processed as JSON data.  YUI can be used to
generate your JSON data, please read the documentation at
http://developer.yahoo.com/yui/json/

asyncRequest will not mess up any requests, I've thoroughly used YUI
in conjunction with C::C::REST and it has never let me down (IE6 is a
different story).  As long as you stick to POST and GET, IE6 will be
fine.

Also, using Dumper inside of your controller is not recommended,
simply use the $c->log->_dump command.  Additionally, using
$c->req->body is what C::C::REST uses, and after the deserialization
the data will be in $c->req->data and a simple:
  $c->log->_dump( $c->req->data );
shows what exactly is in the request data that has been deserialized for use.



More information about the Catalyst mailing list