0

代码从一些教程修改如下:

xmlhttp=new XMLHttpRequest();
var url = "get_data.pl";    
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        alert(xmlhttp.responseText);
    }
}
xmlhttp.send(null);

我希望执行 get_data.pl 脚本并返回运行结果(打印字符串“test”),但我只在 xmlhttp.responseText 中获得了 get_data.pl 的所有行。我应该怎么做?

get_data.pl 如下:

#!C:/Perl/bin/perl.exe
use strict;
use warnings;

&main;

sub main()
{   
print "test";// I'd like the script being executed by Perl interpreter and return the string "test" .   
}

是的,Gar,你是对的,谢谢。我正在使用 Apache,我修改了 httpd.conf 的处理程序行(取消注释并添加 .pl),如你所说。现在问题似乎已解决,但我收到另一个错误:POST http://localhost/get_data.pl 403 (Forbidden)

我将 get_data.pl 放在 htdocs 文件夹中,并且已经将安全选项(OS Win7)设置为执行权限。那为什么被禁止你能再次帮助我?是的,我已经从命令行运行 .pl 并且没有错误。通常 .pl 放在 cgi-bin 文件夹中,该文件夹是带有“htdocs”的兄弟文件夹。当我将 .pl 放入 /cgi-bin 并将 url 修改为“../cgi-bin/get_data.pl”时,我收到错误 500,我猜服务器没有找到该文件。那么我在 httpd.conf 中错过的任何其他配置?无论如何,我将其移至 htdocs 文件夹以避免错误 500 ...

4

1 回答 1

1

请确保您已将处理程序添加到 http 服务器中的 .pl 文件。

于 2013-09-16T15:53:35.140 回答