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


In reply to Re^2: Call Perl script from Javascript by Don Coyote
in thread Call Perl script from Javascript by fattahsafa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.