I wrote a small piece of perl code using CGI::Ajax.
I named the above code as mytest.pl. If I construct a url like this:
The blue section works, but the red section does not work. Could someone tell what I have missed here?
Thanks!
Code:
#! /usr/bin/perl
use strict;
use CGI::Pretty qw( :html3 );
use CGI::Ajax;
local $| = 1;
my $q = new CGI::Pretty;
my $p = new CGI::Ajax('js_func' => \&pl_func);
my $flag = 1; [b]# if $flag != 1, then the Ajax codes would not work!![/b]
[COLOR=blue]
if($flag == 1) {
if($q->param('switch') == 1) {
print $q->redirect('[URL unfurl="true"]http://www.cnn.com');[/URL]
}
else {
print $p->build_html($q, \&Show_HTML);
}
}[/color][COLOR=red]
else {
if($q->param('switch') == 1) {
print $p->build_html($q, \&Show_HTML);
}
else {
print $q->redirect('[URL unfurl="true"]http://www.cnn.com');[/URL]
}
}[/color]
exit 0;
sub Show_HTML {
my $form = &getFormInfo;
my $html = <<HTML;
<html>
<body>
<form action="#" name="theFrom">
$form
</form>
</body>
</html>
HTML
return $html;
}
sub pl_func {
my $fn = shift;
my $ln = shift;
# In reality, will massage $fn & $ln based on some business rule
return $fn.'-'.$ln;
}
sub getFormInfo {
my $info = div(
div($q->label('First Name: '),$q->input({-name=>'fname',-id=>'fnameID',-type=>'text'})),
div($q->label('Last Name: '), $q->input({-name=>'lname',-id=>'lnameID',-type=>'text'})),
div($q->label('Login ID: '), $q->input({-name=>'id',-id=>'idID',-type=>'text', -onfocus=>"js_func(['fnameID', 'lnameID'], ['idID']);"})),
div($q->submit({-value=>"Submit"}), $q->reset({-value=>"Cancel"})));
return $info;
}
I named the above code as mytest.pl. If I construct a url like this:
The blue section works, but the red section does not work. Could someone tell what I have missed here?
Thanks!