naveed010 has asked for the wisdom of the Perl Monks concerning the following question:

Most gracious of monks.

I've written a small input form for a local charity, I decided to use CGI::Ajax as a learning experience for myself.

However, I feel ashamed and am having a complete BrainFart, and have gotten to the point of forgetting how to do the simplest. I'm making a small stupid mistake here and I can't see it.

When the user hits "submit" the fields are passed to a sub in another file, using CGI::Ajax. However, I keep getting an error stating

CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers

It is obviously telling me there's something wrong with my paramaters, however doing something as simple as this:

#!/usr/bin/perl sub insertVals { my $str="num:".scalar(@_); for(my $i=1;$i<scalar(@_);$i++) { $str=$str."<p>$_"; } return $str; }

... returns the CGI error. If I simply do this:

#!/usr/bin/perl sub insertVals { return "num:".scalar(@_); }

It displays num:10 as expected.

Lastly, here's the code that's calling the procedure:

insertVals(['pTD','pLocation','p1','p2','p3','p4','p5','pNum','pGameNo +tes','pGameId'], ['dbPostDiv'] );

I'm stuck in a loop here and need help out. I am wondering if anyone encountered this before? Should I check and see if the paramater is undefined? And, as always, if anyone knows of a better way, I'm all ears.

Thanks in advance. I shall sacrifice the wings of chickens and bottles of ale in appreciation of any help. :)

Additional thoughts... Using CGI::Ajax, how can I retreive the entire http string that's passed to the perl function ie: http://www.mysite.com/ajax.pl?param1=balh¶m2=bwagh.... etc..

Thanks again.

Replies are listed 'Best First'.
Re: CGI::Ajax and passing the paramaters.
by toolic (Bishop) on May 06, 2008 at 18:31 UTC
    When I use the strictures:
    use warnings; use strict;

    I get this type of message:

    Use of uninitialized value in concatenation (.) or string

    because $_ has not been assigned a value. Did you mean?

    $str=$str."<p>$i";

    Update: Or perhaps you wanted something like this:

    use warnings; use strict; my $str = insertVals(qw(pTD pLocation p1 p2 p3 p4 pGameId dbPostDiv)); print "str = $str\n"; sub insertVals { my $str = 'num:' . scalar @_; for (@_) { $str .= "<p>$_" } return $str; }

    prints:

    str = num:8<p>pTD<p>pLocation<p>p1<p>p2<p>p3<p>p4<p>pGameId<p>dbPostDi +v
      I'm more looking to access the values contained in the variables, ie. pTD, pLocation, p1... etc are all values going to be inserted in a MySQL DB.
Re: CGI::Ajax and passing the paramaters.
by Anonymous Monk on May 13, 2008 at 12:22 UTC
    CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers

    It is obviously telling me there's something wrong with my paramaters
    No. It is telling you that you are not implement the CGI protocol. CGI Help Guide

    Using CGI::Ajax, how can I retreive the entire http string that's passed to the perl function ie: http://www.mysite.com/ajax.pl?param1=balh¶m2=bwagh.... etc..
    Use CGI.pm's self_url