The code below was giving a null string with CGI::Ajax-0.681 I am using modperl1 and apache1. I did get a patch from Brian Thomas.
--- lib/CGI/Ajax.pm (revision 95) +++ lib/CGI/Ajax.pm (working copy) @@ -996,8 +996,9 @@ return("") if not defined $func_name; return("") if $func_name eq ""; my $rv = ""; - my $script = $0; - $script =~ s/.*[\/|\\](.+)$/$1/; + my $script = $ENV{'REQUEST_URI'}; my $outside_url = $self->url_list()->{ $func_name }; my $url = defined $outside_url ? $outside_url : $script; if ($url =~ /\?/) { $url.='&'; } else {$url.='?'}
Then make the following change to your script. Change this line:
to this...print $pjx->build_html( $cgi, &Show_HTML($env),$env );
print $pjx->build_html( $cgi, \&Show_HTML($env));
Actually, to pass the sub by ref I have to do this:
my $ref_show = \&Show_HTML; my $show = $ref_show->($env);
However, I noticed this on another occassion, so it has probably nothing to do with the ajax module.
So here is the working code. HOWEVER.. Brian Thomas noticed a couple of '1's at the beginning, which I do not see. So for some things the mystoury continues...
<Location /pjx> SetHandler perl-script PerlInitHandler Apache::StatINC PerlHandler Test::pjx PerlSetVar DBASE ** PerlSetVar DBUSER ** PerlSetVar DBPASS ** </Location>
package Test::pjx; use strict; use Apache::Constants qw(:common); use CGI qw(:all); # or any other CGI:: form handler/decoder use CGI::Ajax; use warnings; use diagnostics; $^W=1; local $SIG{__WARN__} = \&Carp::cluck; sub handler { my $r = shift; my $env = $r->subprocess_env; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func ); my $ref_show = \&Show_HTML; my $show = $ref_show->($env); print $pjx->DEBUG(1); print $pjx->JSDEBUG(1); print $pjx->build_html( $cgi, $show); return OK; } sub perl_func { my $input = shift; # do something with $input my $output = $input . " was the input!"; return $output ; } sub Show_HTML { my $env = shift; my $html = <<EOHTML; <HTML> <BODY > Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_func( ['val1'], ['resultdiv'] );" > <br> <div id="resultdiv" ></div> </BODY> </HTML> EOHTML return $html; } 1; __END__
Screenoutput: http://simulator.bla.nl:8080/pjx Enter something: arnold4 was the input! /pjx?fname=exported_func&args=arnold4&val1=arnold4 ^^^^^ Used to be null, so correct now
In reply to CGI::Ajax gives 'null' scriptname by APvanKampen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |