2015-12-14 59 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

是的,它可以工作,但它取決於你實際發生的事情嗎? 或者你有內部服務器錯誤嗎?如果是這樣,從錯誤日誌中發佈錯誤消息。 –