gpt4 book ai didi

JavaScript 未与 Perl CGI 一起运行

转载 作者:行者123 更新时间:2023-11-28 18:42:08 25 4
gpt4 key购买 nike

在cgi-bin文件夹中,我有一个experiment.cgi:

#!/usr/bin/perl -w

use DBI;
use CGI qw(:standard);
require "../common/config.pl";

print header;
print start_html(-title=>"Add Assignment");


print<<EOT;
<script type = "application/javascript" src = "experiment.js"></script>
EOT

print h2("Add New Automated Assignment");

# print<<AEOT;
# <script>experiment();</script>
# AEOT
print end_html;

在同一个文件夹中我有experiment.js

function experiment(){
alert('ghello world');
}

但是,experiment.js 文件包含存在问题。在日志文件中,我收到以下错误:

End of script output before headers: experiment.js

我搜索了这个错误,发现它与cgi文件有关。所以我的猜测是apache2正在将experiment.js解释为cgi文件。我的说法正确吗?如果是,正确的设置方法是什么,以便 JavaScript 和 cgi 可以一起使用?

最佳答案

I searched for this error and found it was relate to cgi files. So my guess is that apache2 is interpreting experiment.js as a cgi file. I am right in this?

是的

If yes, what is the proper way to setup so that javascript and cgi could be used together.

不要将非 CGI 程序放入您的 cgi-bin 中。将它们与其余静态文件放在一起。

您需要调整网址。例如,src="/js/experiment.js"

关于JavaScript 未与 Perl CGI 一起运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35968495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com