CGI-Ajax

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

pod2text CGI::Perljax.pm > README

CGI::Perljax

Perljax - a perl-specific system for writing AJAX- or
DHTML-based web applications.


Perljax provides a unique mechanism for using perl code
asynchronously from javascript using AJAX to access user-written
perl functions/methods. Perljax unburdens the user from having to
write any javascript, except for having to associate an exported
method with a document-defined event (such as onClick, onKeyUp,
etc). Only in the more advanced implementations of a exported perl
method would a user need to write custom javascript. Perljax supports
methods that return single results, or multiple results to the web
page. No other projects that we know of are like Perljax for the
following reasons: 1. Perljax is targeted specifically for perl
development. 2. Perljax shields the user from having to write any
javascript at all (unless they want to).  3. The URL for the HTTP GET

lib/CGI/Ajax.pm  view on Meta::CPAN


    CGI::Ajax->mk_accessors(@METHODS);

    $VERSION = .707;
}

########################################### main pod documentation begin ##

=head1 NAME

CGI::Ajax - a perl-specific system for writing Asynchronous web
applications

=head1 SYNOPSIS

  use strict;
  use CGI;      # or any other CGI:: form handler/decoder
  use CGI::Ajax;

  my $cgi = new CGI;
  my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func );

lib/CGI/Ajax.pm  view on Meta::CPAN

  $pjx->skip_header(1);
  
  print $pjx->build_html( $cgi, \&Show_HTML);

I<There are several fully-functional examples in the 'scripts/'
directory of the distribution.>

=head1 DESCRIPTION

CGI::Ajax is an object-oriented module that provides a unique
mechanism for using perl code asynchronously from javascript-
enhanced HTML pages.  CGI::Ajax unburdens the user from having to
write extensive javascript, except for associating an exported
method with a document-defined event (such as onClick, onKeyUp,
etc).  CGI::Ajax also mixes well with HTML containing more complex
javascript.

CGI::Ajax supports methods that return single results or multiple
results to the web page, and supports returning values to multiple
DIV elements on the HTML page.

lib/CGI/Ajax.pm  view on Meta::CPAN

If method() isn't available, it creates it's own minimal header.

A primary goal of CGI::Ajax is to keep the module streamlined and
maximally flexible.  We are trying to keep the generated javascript
code to a minimum, but still provide users with a variety of
methods for deploying CGI::Ajax. And VERY little user javascript.

=head1 EXAMPLES

The CGI::Ajax module allows a Perl subroutine to be called
asynchronously, when triggered from a javascript event on the
HTML page.  To do this, the subroutine must be I<registered>,
usually done during:

  my $pjx = new CGI::Ajax( 'JSFUNC' => \&PERLFUNC );

This maps a perl subroutine (PERLFUNC) to an automatically
generated Javascript function (JSFUNC).  Next you setup a trigger this
function when an event occurs (e.g. "onClick"):

  onClick="JSFUNC(['source1','source2'], ['dest1','dest2']);"

scripts/pjx_combo.pl  view on Meta::CPAN

my %hash = ( 'SetA'         => \&set_listA,
             'SetB'         => \&set_listB,
             'ShowResult'   => \&show_result );

my $pjx = CGI::Ajax->new( %hash ); # this is our CGI::Ajax object
$pjx->js_encode_function('encodeURIComponent');

$pjx->DEBUG(1);   # turn on debugging
$pjx->JSDEBUG(1); # turn on javascript debugging, which will place a
                  #  new div element at the bottom of our page showing
                  #  the asynchrously requested URL

print $pjx->build_html( $q, \&Show_HTML ); # this builds our html
                                           #  page, inserting js

# This subroutine is responsible for outputting the HTML of the web
# page.  Note that I've added an additional javascript function to
# erase/reset contents.  This prevents strange effects from
# overwriting a div without clearing it out first.
sub Show_HTML {
  my $html = <<EOT;

scripts/pjx_radio.pl  view on Meta::CPAN

my $q = new CGI;  # need a new CGI object

# compose our list of functions to export to js
my %hash = ( 'myFunc'         => \&perl_func,);

my $pjx = CGI::Ajax->new( %hash ); # this is our CGI::Ajax object

$pjx->DEBUG(1);   # turn on debugging
$pjx->JSDEBUG(1); # turn on javascript debugging, which will place a
                  #  new div element at the bottom of our page showing
                  #  the asynchrously requested URL

print $pjx->build_html( $q, \&Show_HTML ); # this builds our html
                                           #  page, inserting js

# This subroutine is responsible for outputting the HTML of the web
# page. 
sub Show_HTML {
  my $html = <<EOT;
<HTML>
<HEAD><title>Radio Example</title>



( run in 0.245 second using v1.01-cache-2.11-cpan-0d8aa00de5b )