[cgiapp] [OT] Anyone using JSON::XS to output to a web page?
Peter Karman
peter at peknet.com
Fri Oct 10 21:17:18 EDT 2008
Ron Savage wrote on 10/10/08 7:48 PM:
> Hi Folks
>
> I'm using YUI (Yahoo User Interface) to display JSON data hard-coded in
> the web page. But when I send the data from my CGI::App, it is not
> displayed. Here's the core Javascript:
>
> var json_data = new YAHOO.util.LocalDataSource
> (
> {results:
> [
> {name: "Ron Savage", email: "ron at savage.net.au", phone: "0"},
> {name: "Zoe Savage", email: "zoe at savage.net.au", phone: "9"}
> ]
> }
> );
>
> If I replace the above with this, where o.responseText is returned from
> the server via Ajax:
>
> json_data = new YAHOO.util.LocalDataSource(o.responseText);
>
> the datasource displays "No records found.".
>
> The Perl code on the server is:
>
> return encode_json {results => [map { {email => $$_{'email'}, name =>
> $$_{'name'}, phone => $$_{'phone'} } } @people]};
>
> Any ideas?
>
I use JSON::XS with YUI and CatalystX::CRUD::YUI and it works well. You can see
how I encode here:
http://search.cpan.org/src/KARMAN/CatalystX-CRUD-YUI-0.006/lib/CatalystX/CRUD/YUI/TT.pm
My first guess is that the data structure you are sending to the client is not
what you have YUI configured to receive. Try wget (or similar) to see what the
JSON is by making the same request that your AJAX call makes.
And if you haven't tried it yet, get Firebug for Firefox. I can't imagine doing
JS devel anymore without it. It's like the Perl debugger plus Data::Dumper plus
a Dom detective all in one.
--
Peter Karman . http://peknet.com/ . peter at peknet.com
More information about the cgiapp
mailing list