InfiniteLoop has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks
 
Im in the process of using asynchronous javascript (current jargon: ajax) with my CGI::Application based application.

Replies are listed 'Best First'.
Re: perl & Asynchronous Javascript
by shiza (Hermit) on Aug 10, 2005 at 20:49 UTC
    All you need to do is return an valid XML document. You can also set content-type to text/xml which will automatically force it into an XML object when received by your Javascript.
Re: perl & Asynchronous Javascript
by jplindstrom (Monsignor) on Aug 10, 2005 at 21:05 UTC

      You can do the same with CGI::Application through the CGI::Application::Plugin::HTMLPrototype plugin. It has a couple examples to show you how to use it as well.

      You don't have to change anything you do in CGI::Application when you use the prototype library. All AJAX calls are just standard GET or POST requests to your application, and the only difference is that usually you only return a small piece of HTML that gets placed into the existing page somewhere instead of returning a full HTML page.

Re: perl & Asynchronous Javascript
by gryphon (Abbot) on Aug 11, 2005 at 02:22 UTC

    Greetings InfiniteLoop,

    As I mention here and here, I'm a big fan of JSON (JavaScript Object Notation) and the JSON.pm module from CPAN. When used with CGI::Application, you just return the JSON-created string out of the subroutine that's setup by setup instead of your normal template content. It's crazy-simple.

    Here's some sample code...

      Thanks a bunch [id://gryphon], this is most excellent help.