我有一个ajax代码,我通过使用GET方法进行查询来调用Perl脚本。
Ajax代码
if(ajaxRequest != null)
{
ajaxRequest.open("GET", "dial1.pl" + queryString , true);
ajaxRequest.onreadystatechange = handler;
//console.log(queryObj.fund);
ajaxRequest.send(null);
}
Perl Code
#!/usr/bin/perl -w
# Dial Script for asterisk
# date: 25 July 2013
use strict;
use CGI;
use Fcntl;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = new CGI;
my ($request,$agent_id,@agent_details_url,$agent_name,$agent_terminal_id);
if ($ENV{'REQUEST_METHOD'} eq "GET")
{ # if we're receiving a GET
$request = $ENV{'QUERY_STRING'}; # the request is passed in the
} # environment variable
# QUERY_STRING
# else ...
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{ # if receiving a POST request
# the length of the posted data
# is passed in CONTENT_LENGTH,
# and it is read from stdin
#$request = $ENV{'QUERY_STRING'};
read(STDIN, $request,$ENV{'CONTENT_LENGTH'}) || die "Could not get query\n";
}
my $context="Test";
my $query_string="$request";
$query_string=~ s/&//;
my @new_query_string = split(/=/,$query_string);
my $phone=$new_query_string[1];
print "<p>alert($phone)</p>";
print $cgi->header();
print $cgi->start_html('Asterisk Caller');
print '<center><p>call</p>';
sysopen( FH,"/var/spool/asterisk/outgoing/meeting_user$$.call", O_RDWR|O_EXCL|O_CREAT, 0777);
#print FH "Channel: GSM/1/xxxxxxxxx\n";
#print FH "Channel: GSM/1/$phone\n";
print FH "Callerid: 4006\n";
print FH "RetryTime: 60\n";
print FH "WaitTime: 30\n";
print FH "Context: $context\n";
print FH "Extension: s\n";
#printf "<p><b>$dest_nmbr<\/b> über <b>$src_nmbr<\/b><\/p>";
close FH;
当我手动运行Perl程序时,它工作正常,另一方面我通过ajax(使用浏览器)收到错误
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 62.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 64.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 65.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 66.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 67.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 68.
请告诉我我在哪里做错了,并感谢您的建议。