Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

perl & Asynchronous Javascript

by InfiniteLoop (Hermit)
on Aug 10, 2005 at 20:45 UTC ( [id://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 [id://gryphon], this is most excellent help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found