User Tools

Site Tools


Here is an example of transmitting a form using jquery post to a perl cgi script.

$(document).ready(function() {

    var formData = $("form#xapian").serialize();
    var jsonData = JSON.stringify(formData);"/cgi-bin/jwl/getdata.cgi",jsonData,success=function(data,textStatus,jqXHR)
            console.log("data returned raw "+data);

Perl code:

use strict;
use JSON;
use Data::Dumper;
open OUT,">","/tmp/perl.out";
print "Content-Type: text/html; charset=windows-1251\n\n";
my $buffer;
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
my $json = decode_json($buffer);
print OUT "Splitting\n";
my @pairs = split(/&/, $json);
my $n=scalar(@pairs);
print OUT "THere are $n values\n";
#print OUT Dumper(@pairs);
my %FORM;
foreach my $pair (@pairs) 
    my ($name, $value) = split(/=/, $pair);

    $FORM{$name} = $value;

print OUT "Printing form\n";
print OUT Dumper(%FORM);

Output (edited):

THere are 24 values
Printing form
$VAR1 = 'query';
$VAR2 = '                    ';
$VAR3 = 'xSORT';
$VAR4 = '_OSORT_';
$VAR5 = 'xDB';
$VAR6 = '_ODB_';
$VAR7 = 'xTERMS';
$VAR8 = '_OTERMS_';
$VAR9 = 'xAND';
$VAR10 = '_OAND_';
$VAR11 = '';
$VAR12 = '';

Dump is weird. It dumps hashes as an array of pairs so this is what the hash really looks like:


Also one way to initialize a hash:

my %rec_hash = ('name'=>$name, 'type'=>$type,'data'=>$data,'ttl'=>$ttl);
cgi_jquery.txt · Last modified: 2022/10/17 12:57 by admin