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:

print $pjx->build_html( $cgi, &Show_HTML($env),$env );
to this...
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.