【问题标题】:How to call a perl script in html如何在html中调用perl脚本[重复]
【发布时间】:2017-11-28 10:47:50
【问题描述】:

如何调用在 html 文件中返回数据“文本”类型的 perl 脚本。发布 perl 脚本以供参考。这个脚本必须在 index.html 中调用,所以如何做到这一点

#!/usr/bin/perl -w  

use CGI;  

my $cgi = CGI->new;  
my $remote = $cgi->remote_host();  

my $AB = "16.108";  
my $CD = "16.214";  
my $EF = "10.99";  
my $GH = "10.243";  
my $XY = "10.179";  

my @remote_ip_values = split(/\./, $remote);  

my $remote_ip = $remote_ip_values[0] .".". $remote_ip_values[1];  

print "Content-type: text/html\n\n";  
print "document.write(\"<style>\\n\");\n";  
print "document.write(\"font color:red;\\n\");\n";  


if ($remote_ip eq $AB)  
{  
print "document.write(\"SUCCESSFUL\");\n";  

}  
 else  
{  
print "document.write(\"TEST\");\n";  
}  
exit;  

【问题讨论】:

标签: html perl perl-module perlscript


【解决方案1】:

我正在编辑我的答案,因为我现在了解您要做什么。我已经设置了一个简单的示例,它将从“另一个网站”加载内容 - 对您而言将是您的 Perl CGI。

这个 HTML 使用了一些简单的 JQuery。我正在加载以下 HTML 页面,http://chocksaway.com/tester.html 并将内容复制到“测试”div 中:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Loader</title>
    </head>
    <body>
        <div id="test"></div>
            <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#test').load('http://chocksaway.com/tester.html');
                });
            </script>
    </body>
</html>

http://chocksaway.com/tester.html 具有以下 HTML:

<html>
    <header></header>
    <body> 
        this is a test so there
    </body>
</html>

如果你打开http://chocksaway.com/tester2.html,你会看到:

this is a test so there

将“http://chocksaway.com/tester2.html”替换为 Perl CGI 的 URL

【讨论】:

  • 是的,该脚本正在浏览器中运行。我在浏览器中获得了所需的文本。现在我想要在 index.html 中调用此脚本,以便索引网页获得所需的文本和其他东西
  • 您可以使用ajax 和JQuery 进行调用。这将允许您调用您的 Perl CGI。这会调用天气 API。 gist.github.com/npearson72/4102982 '做'我所描述的。
  • 我已经用一个实际的例子更新了答案,它向您展示了如何使用一些 Javascript / JQuery 将 CGI 的内容加载到“div”中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 2013-06-09
  • 1970-01-01
相关资源
最近更新 更多