简体   繁体   English

CGI脚本问题

[英]Problems with CGI Script

A user has to type some text into a text field which is declared as a form in my HTML. 用户必须在文本字段中输入一些文本,该文本字段在我的HTML中声明为表单。 Some JavaScript code prints the user's input which has been processed by a CGI script. 一些JavaScript代码会打印用户的输入,这些输入已由CGI脚本处理。

JavaScript 的JavaScript

function xmlHttpPost(strURL) {var xmlHttpReq;
// Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
// IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.timeout = 0;
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-    urlencoded');
    xmlHttpReq.onreadystatechange = function() {
        if (xmlHttpReq.readyState == 4) {
            updatepage(xmlHttpReq.responseText);
        }
    }
    var form = document.forms['f1'];
    var query = form.word.value;
    xmlHttpReq.send("key=" + query);
}

function updatepage(str){
    document.getElementById("result").innerHTML = "Result:" + "<br/>" + str;
}

CGI CGI

#!"G:\xampp\perl\bin\perl.exe"

use CGI;

$query = new CGI;
$key = $query->param('key');
print $query->header;
print "<h1>The key is $key</h1>"

When I type something into the form and submit the data Error 500 occurs: 当我在表单中键入内容并提交数据时,发生错误500:

End of script output before headers: ajax-echo.cgi 标头之前的脚本输出结束:ajax-echo.cgi

This is what Apache's error.log says 这就是Apache的error.log所说的

AH01215: Can't locate CGI.pm in @INC (@INC contains: .) at G:/xampp/cgi-bin/ajax-echo.cgi line 7.\\r, referer: http://localhost/ajax.html?word=test AH01215:无法在G:/xampp/cgi-bin/ajax-echo.cgi第7行的@INC中找到CGI.pm(@INC包含:。),\\ r,引用网址:http:// localhost / ajax。 html?word = test
AH01215: BEGIN failed--compilation aborted at G:/xampp/cgi-bin/ajax-echo.cgi line 7.\\r, referer: http://localhost/ajax.html?word=test AH01215:BEGIN失败-在G:/xampp/cgi-bin/ajax-echo.cgi第7行中,编译中止。\\ r,引荐来源: http://localhost/ajax.html?word = test

There's a newly installed and configured XAMPP installation on my USB stick. USB记忆棒上有一个新安装并配置的XAMPP安装。 It has every permission it needs to run properly. 它具有正常运行所需的所有权限。

The important part of the error message is this: 错误消息的重要部分是:

Can't locate CGI.pm in @INC (@INC contains: .)

The search path for modules just contains the current directory "." 模块的搜索路径仅包含当前目录“。” and obviously there is no CGI.pm in the current directory. 显然,当前目录中没有CGI.pm。

Try to find the directory, where CGI.pm is installed, and then add this line to your Apache configuration 尝试找到安装CGI.pm的目录,然后将此行添加到您的Apache配置中

SetEnv PERL5LIB "G:/xampp/path/to/module/directory"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM