JayBee has asked for the wisdom of the Perl Monks concerning the following question:
and here's all of the param.pl file$(function(){ // $Date is perl of course var json=jQuery.parseJSON(\'{"DATE":"'.$Date.'"}\'); json["address"]="123 some street"; // other functions generate more fields. and call postM() postM(); function postM(){ $.ajax({ url: "params.pl", type: "GET", processData: false, data: JSON.stringify(json), dataType: "text", async: true, success: function(msg){ alert("perl says: "+msg); } }); // ajax } // postM }); // jquery
This works ok while jquery sections has type: "GET" but read POST is better way to handle things, though it fails if I change it. Also, when I do get the data, there's a bunch of backslashes and I feel there's got to be a better way. Also note: "processData" is set to false with jquery since I don't know the exact parameter names being transferred. Any help would be appreciated. Thank you perl monk masters.#!/usr/bin/perl use strict; use CGI ':standard'; use CGI::Carp "fatalsToBrowser"; my $req=$ENV{QUERY_STRING}; my $i='0'; my $ref=$ENV{HTTP_REFERER}; my $p=param('data'); my $ad=param('address'); my $num_args = $#ARGV + 1; $i++ if $p; $i++ if $ad; $i++ if $req; my $file='json.txt'; open FH,'>',$file; print FH "R:$ref Q:$req A:$ad P:$p G:$ARGV[0] "; close FH; wait; my $fsz= -s $file; print header,"file Sz:$fsz ARGV: $num_args I: $i";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Receiving JSON data with perl
by Anonymous Monk on Aug 10, 2016 at 23:08 UTC | |
by JayBee (Scribe) on Aug 11, 2016 at 23:24 UTC | |
|
Re: Receiving JSON data with perl
by duyet (Friar) on Aug 11, 2016 at 06:19 UTC | |
by Anonymous Monk on Aug 11, 2016 at 06:35 UTC | |
by JayBee (Scribe) on Aug 11, 2016 at 23:34 UTC |