What a bunch of poopy answers
Hi,
You need to organize your code (make subs with meaningful names), its like 2nd day programming stuff that people forget about until a framework slaps them in the face with the requirement, but you don't have to be unconcious about it, take charge of your code, give it name, like you would a stuffed animal, it makes playtime all the more interesting
Like this, this is you foo.cgi or foo.pl
#!/usr/bin/perl --
use strict;
use warnings;
use MyStuff;
Main( @ARGV );
exit( 0 );
sub Main {
MyStuff::RunCGI({ 'dbconfig' => { } });
## print MyStuff::ThisPage( CGI->new({ page => 'thisone', debug=>1,
+in => 'making sure this works, dev, debug'} ) );
}
This is your MyStuff.pm package MyStuff;
use HTML::Template;
use strict;
use warnings;
use CGI();
sub MyStuff::RunCGI {
my $q = CGI->new;
my( $headers, $body ) = MyStuff::DispatchCGI( $q );
print $headers, $body;
}
sub MyStuff::DispatchCGI {
my( $q ) = @_;
my $page = $q->page || 'default';
$page = 'ajax' if $q->request_method eq 'POST' and ...;
return ThisPage( $q ) if $page eq 'thisone';
return ThatPage( $q ) if $page eq 'thatone';
return AjaxPage( $q ) if $page eq 'ajax';
}
sub MyStuff::ThisPage {
my( $q ) = @_;
my $template = HTML::Template->new ...;
$template->param( foo => scalar $q->param('foo') );
...
...
return $q->headers, $template->output;
}
sub MyStuff::AjaxPage {
my( $q ) = @_;
...
return $headers, $body;
}
Your html template should include/link these two javascript files jquery.js myecho.js you can get example myecho.js from Mojolicious::Lite +and jQuery +AJAX + Mojo::Template, it uses jquery to make a http request to a url and retrieve some data from it, and update the webpage/dom/display/divtag the user sees
more subs, cgi101, learn about the internet
|