我如何使用jQuery的/ JavaScript变量的值在Perl脚本?如何使用、变量、脚本、JavaScript

由网友(最后的守望者)分享简介:我是一个完整的新手到Perl的&放大器;使用Javascript / jQuery的/阿贾克斯。举个例子,我想发送字符串变种 exampleString 来test.pl,脚本然后将写入文件的字符串。I am a complete newbie to Perl & Javascript/Jquery/Ajax. As...

我是一个完整的新手到Perl的&放大器;使用Javascript / jQuery的/阿贾克斯。举个例子,我想发送字符串变种 exampleString 来test.pl,脚本然后将写入文件的字符串。

I am a complete newbie to Perl & Javascript/Jquery/Ajax. As an example, I'd like to send the string var exampleString to test.pl, and the script will then write the string to file.

function sendToScript{
    var exampleString = 'this is a string';
    $.ajax({
            url: './test.pl',
            data: exampleString,
            success: function(data, textStatus, jqXHR) {
                alert('string saved to file');
            }
}

test.pl

test.pl

#!/usr/bin/perl -w
use strict;

#How do I grab exampleString and set it to $string?

open (FILE, ">", "./text.txt") || die "Could not open: $!";
print FILE $string;
close FILE;

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

推荐答案

您可能要像

var exampleString = 'this is a string';
$.ajax({
    url: './test.pl',
    data: {
        'myString' : exampleString
    },
    success: function(data, textStatus, jqXHR) {
        alert('string saved to file');
    }
});

和test.pl

#!/usr/bin/perl -w
use strict;

use CGI ();
my $cgi = CGI->new;
print $cgi->header;
my $string = $cgi->param("myString");

open (FILE, ">", "./text.txt") || die "Could not open: $!";
print FILE $string;
close FILE;
阅读全文

相关推荐

最新文章