CGI::Ajax

This Ajax stuff is really quite easy :-)

Dominic Mitchell (dom@happygiraffe.net)

London JavaScript Night, May 2006

happygiraffe.net/presentations/cgi-ajax-lightning

$Id: index.html 796 2006-05-24 23:30:02Z dom $

Links from the slide:

  • http://happygiraffe.net/presentations/cgi-ajax-lightning/

Bob, we need Ajax!

What is Ajax?

How can I implement it?

This is your CGI

  #!perl -w
  use strict;
  use CGI;

  my $cgi = CGI->new();
  print $cgi->header();
  # ... exercise for the reader ...
  print $template->output();

  # Do something dynamic.
  sub uptime { `uptime` }

This is your CGI on Ajax

  #!perl -w
  use strict;
  use CGI;
  use CGI::Ajax;

  my $cgi = CGI->new();
  my $ajax = CGI::Ajax->new( uptime => \&uptime );
  print $ajax->build_html( $cgi, \&main );

  sub main {
    print $cgi->header();
    # ...
    print $template->output();
  }

  # Do something dynamic.
  sub uptime { `uptime` }

Serve with a dash of JavaScript

  <div>
    <input type="button" name="uptime" value="Uptime?" 
      onclick="uptime([],['overhere'])" />
    <span id="overhere"/>
  </div>

CGI::Ajax

Links from the slide:

  • http://search.cpan.org/dist/CGI-Ajax/

More Details

perl.com/pub/a/2006/03/02/ajax_and_perl.html

Links from the slide:

  • http://www.perl.com/pub/a/2006/03/02/ajax_and_perl.html