2015-12-14 58 views
-2

如何在浏览器上加载html页面时运行perl脚本。我试图运行perlscript onload(),甚至将它写在头上。但没有奏效 perl脚本:在加载html页面上运行perl脚本

#!/usr/bin/perl -w 
use strict; 
use CGI ':standard'; 
use warnings; 
use FileHandle; 

my $result="sakshi"; 

open(OUT,'>/var/cgi-bin/sample.html'); 
print 
OUT header(), 
start_html(
    -title => 'Command', 
    -text => '#520063' 
); 
print OUT "Hello $result"; 
print OUT end_html(); 
close(OUT); 

事情,我在HTML曾尝试:

1.

<head> 
<title>test</title> 
<script src="common_info.pl"></script> 
</head> 

2.

<body onload=call_perl()"> 
<script text/javascript> 
function call_perl(){ 
var ajax = new XMLHttpRequest; 
ajax.open("GET", "http://localhost/cgi-bin/myscript.pl", true); 
ajax.send(); 
} 
</script> 
+2

你想完成什么?发布的代码没有任何意义。 –

回答

0

在HTML文件:

<html> 
    <head> 
    <title></title> 
    <script type="text/javascript" src="http://localhost/cgi-bin/my_script.pl"></script> 
    </head> 
    <body></body> 
</html> 

在my_script.pl:

#!/usr/bin/perl 

use strict; 
use CGI ':standard'; 
use warnings; 
use FileHandle; 

my $result="sakshi"; 

open(OUT, ">", "/var/www/cgi-bin/sample.html") or die "cannot open > /var/www/cgi-bin/sample.html: $!"; 
print OUT header(); 
print OUT start_html(-title=>'Command',-text=>'#520063'); 
print OUT print("Hello $result"); 
print OUT end_html(); 
close(OUT); 

当我启动的HTML文件,该文件/var/www/cgi-bin/sample.html现在将包含生成的内容:

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> 
<head> 
<title>Command</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
</head> 
<body text="#520063"> 
1 
</body> 
</html> 

希望这个清除它升技

+0

不,它没有工作:( – geek

+1

是的,它可以工作,但它取决于你实际发生的事情吗? 或者你有内部服务器错误吗?如果是这样,从错误日志中发布错误消息。 –