[cgiapp] Ajax and JSON recipe

Bruce McKenzie bruce at 2minuteexplainer.com
Thu Apr 9 12:08:46 EDT 2009


That's how I do it, too. JSON.pm does the outgoing conversion:

sub get_json {
    my $perl_data_structure = shift;
    use JSON; #  imports objToJson
    return objToJson( $perl_data_structure );
}

jQuery has lots of tools for handling incoming JSON and for sending form
data to CGI::Application webapps (where it will be handled by CGI.pm).

Cheers,

Bruce


--
Bruce McKenzie
Business Information Graphics, Inc.
New York

http://www.2MinuteExplainer.com
212-477-4288



On Thu, Apr 9, 2009 at 11:20 AM, P Kishor <punk.kish at gmail.com> wrote:

> On Thu, Apr 9, 2009 at 9:53 AM, Lyle Brooks <brooks at deseret.com> wrote:
> > I have a need to incorporate Ajax calls with JSON data into
> > our application.  I was looking for something in terms of a piece
> > of "starter" code or a recipe.  I didn't see anything on the website
> > related to it.
> >
> > CGI Application seems like such a robust framework, that this should be
> > a natural fit.
> >
> > Does anyone have a short starter example of code (both server and client)
> > that they would be willing to post/share that would show Ajax/JSON
> > usage with CGI::Application?
>
> Short advice... don't. That is, don't mix CGI::App in the backend with
> Ajax in the front-end. Keep separate things separate.
>
> Create your JSON stream (I query the db, and convert the result set
> into JSON using JSON.pm) and send it back to the client via
> HTML::Template (I have a simple, one variable template with <TMPL VAR
> JSON_DB_QUERY> or something like that).
>
> Use your favorite way of manipulating the data on the client (I use
> jQuery to initiate the Ajax call and to deal with the results).
>
>
> >
> > Thanks much.
> >
> > Lyle Brooks
> >
> > #####  CGI::Application community mailing list  ################
> > ##                                                            ##
> > ##  To unsubscribe, or change your message delivery options,  ##
> > ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> > ##                                                            ##
> > ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> > ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> > ##                                                            ##
> > ################################################################
> >
> >
>
>
>
> --
> Puneet Kishor http://www.punkish.org/
> Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
> Carbon Model http://carbonmodel.org/
> Open Source Geospatial Foundation http://www.osgeo.org/
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
>
>


More information about the cgiapp mailing list