Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

perl & Asynchronous Javascript

by InfiniteLoop (Hermit)
on Aug 10, 2005 at 20:45 UTC ( #482755=perlquestion: print w/replies, xml ) Need Help??

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.
  • Should I code my CGI's in a different way for this ? Do I have to expose the interface(s) via xml-rpc ?
  • Are there any CPAN modules for this ?

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 gryphon, this is most excellent help.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://482755]
Approved by xdg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-12-03 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (55 votes). Check out past polls.

    Notices?