Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't this jQuery.post work with Perl CGI?

Tags:

jquery

cgi

perl

I'm trying to figure out why I'm not seeing params with $.post("/url/", {wtf: 2}).

I'm using this perl:

use strict;
use CGI;

my $cgi = new CGI;
print $cgi->header("text/javascript");
print "'no'";

use Data::Dumper;
warn Dumper({ (map {$_=>$cgi->param($_ )} $cgi->param), postdata=>$cgi->param("POSTDATA") });

When I issue a $.get("/url", {wtf: 2}), I get the results I expect and find wtf is 2 in the logs. When I use $.post("/url/", {wtf: 2}), I don't seem to get any params at all (just a $VAR1 = { postdata=>undef } in the logs).

What am I missing?

Firebug reveals that: Transfer-Encoding is "chunked" and Content-Type is "application/x-www-form-urlencoded; charset=UTF-8". Further, the Post tab seems to show the arguments in the request, but no joy from CGI.

like image 805
jettero Avatar asked Dec 13 '25 19:12

jettero


2 Answers

Could be that your results are coming back neither application/x-www-form-urlencoded nor multipart/form-data. CGI doc has this to say about it:

If POSTed data is not of type application/x-www-form-urlencoded or multipart/form-data, then the POSTed data will not be processed, but instead be returned as-is in a parameter named POSTDATA. To retrieve it, use code like this:

    my $data = $query->param('POSTDATA');
like image 70
Axeman Avatar answered Dec 16 '25 10:12

Axeman


If you've got access to a linux box, you could set up 'nc' (netcat) to listen on port 80 and see the raw requests you're receiving.

I suspect it's a server-side problem though. Perhaps some Apache configuration is interfering? Sorry I can't be more help.

like image 36
aidan Avatar answered Dec 16 '25 12:12

aidan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!