【发布时间】:2017-04-24 07:29:14
【问题描述】:
用户必须在我的 HTML 中声明为表单的文本字段中键入一些文本。一些 JavaScript 代码会打印出经过 CGI 脚本处理的用户输入。
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
#!"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>"
当我在表单中输入内容并提交数据时出现错误 500:
头文件前的脚本输出结束:ajax-echo.cgi
这就是 Apache 的 error.log 所说的
AH01215:在 G:/xampp/cgi-bin/ajax-echo.cgi 第 7 行的 @INC(@INC 包含:.)中找不到 CGI.pm。\r,引用者:http://localhost/ajax.html?word=test
AH01215: BEGIN failed -- 编译在 G:/xampp/cgi-bin/ajax-echo.cgi 第 7 行中止。\r, referer: http://localhost/ajax.html?word=test
我的 U 盘上有一个新安装和配置的 XAMPP 安装。它拥有正常运行所需的所有权限。
【问题讨论】:
-
application/x-www-form- urlencoded是这里的错字还是你的真实代码中的错字? -
在命令行输入
perl -e 'use CGI;'能找到模块吗?另一种可能性是 dos 与 unix 行尾...我提到这一点是因为错误输出中的可疑“\r”...您可以尝试在您的 cgi 脚本上执行dos2unix(或unix2dos)以查看是否它有帮助。 -
显而易见的答案是您的服务器上的 perl 安装没有安装
CGI模块。自 2015 年 6 月发布 v5.22 以来,它一直不是核心模块。
标签: javascript html ajax perl cgi