我如何使用jQuery的/ JavaScript变量的值在Perl脚本? [英] How can I use the value of a JQuery/Javascript variable in a Perl script?
本文介绍了我如何使用jQuery的/ JavaScript变量的值在Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个完整的新手到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;
这篇关于我如何使用jQuery的/ JavaScript变量的值在Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文