Even with code tags, I am a little fuzzy as to how this gets passed to the script.
The $get() function does not state whether this is a post or get request, in that it is a Javascript function which could be doing anything. Looks like a get request though.
To get a list of paramaters you can go a couple of ways see http://search.cpan.org/~markstos/CGI.pm-3.65/lib/CGI.pm#FETCHING_A_LIST_OF_KEYWORDS_FROM_THE_QUERY:
The JSON object containing the word: string once extracted can then be decoded and manipulated. You will then be able to encode back into a JSON object
However as I cannot tell how your calling function is sending - are the Data functions DOM functions or also parameters? - and will this function happily receive the return value from the Perl script?
Assuming the parameters are passed as a list of value pairs, something like this may get the value
#!/usr/bin/perl -T
use warnings;
use strict;
use CGI;
use JSON;
my $q = CGI->new;
my @pars = $q->params;
my $wordref = decode_json($pars[0]);
my $word = $wordref->{word} ;
#untaint word
die "invalid input" unless $word =~ /^([\w\s]+)$/;
$word = $1;
... # mess about with db and/or word;
$wordref->{word} = $word;
my $jsonobj = encode_json($wordref);
But how does it get back? To be honest, I am not completely sure in this case.
The second parameter passed into the script may be the empty value holder so you could extract that and send that back. But this is really dependant on what that Javascript function is doing |