3

I have created a perl script which is getting run time data from server and displaying on a html page. I am not using any databse there.

I have to link another perl script with 1 javascript variable. I want to make that value global so that I can access from anywhere.

Here is the problem

For testing when I include that javascript function inside perl script it alerts me passed value but if I put that function in a js file and call it, it doesn't alert anything. I tried calling js file from multiple locations but no luck :(

Can anybody help me on this asap?

this is code from js file

`$(document).ready(function(){
function aabcd(){
var y=document.getElementById("mnth").value;
alert(y);
}
});
`

Here is the full code.

I am facing problem here I am unable to call this test.js file. If I include this file's contents in this perl script then it works fine but I want to use via file so that I can use those variable as globally. `

#!/usr/bin/perl
#!/bin/ksh


use CGI qw(:standard escapeHTML);
print <<EOH;
Content-Type: text/html; charset=ISO-8859-1

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en" />
<title> ITSS UNIX report</title>

<style type="text/css">
h1 { font-size: 24px; }
body {
     font: 13px tahoma;
     background: #ffffff;
      margin: 1em 2em;
        padding: 0em;
     }
</style>
<link rel="stylesheet" type="text/css" href="/example1.css" />
<script type="text/javascript" src="/DropMenu1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript" src="/test.js"></script>
</head>
<body>


<TABLE WIDTH="100%" cellSpacing=0 cellPadding=1 align=center border=0 style='border: 1px solid; border-width: 0 0 0 0; border-style:solid; margin: 0; padding: 0;' bordercolor=#B
DBDBD>
<TR>
<TD width=100% BGCOLOR=#000066 ALIGN=center><FONT style='font-size: 28.0pt;mso-bidi-font-size: 11.0pt;font-family: tahoma;color: #FFFFFF;background-color=#000066'>User Audit Sec
urity Report</TD>
</TR>
</TABLE>
<form name="myform">
<select name="year" id="year">
<option value="2011">2011</option><option value="2012">2012</option></select>
<select name="mnth" id="mnth" onchange="return aabcd();">
<option value="-1" class="item1" >Click for Month</option>
<option value="Jan" class="item2" >January </option>
<option value="Feb" class="item2" >February</option>
<option value="Mar" class="item2" >March </option>
<option value="Apr" class="item2">April</option>
<option value="May" class="item2" >May </option>
<option value="Jun" class="item2" >June </option>
<option value="Jul" class="item2" >July</option>
<option value="Aug" class="item2" >August </option>
<option value="Sep" class="item2" >September</option>
<option value="Oct" class="item2" >October</option>
<option value="Nov" class="item2" >November</option>
<option class="item2" value="Dec">December</option></select></td></tr>
<input id="sub" value="Submit" type="button">
</form>
4

1 回答 1

1

如果您查看 CGI 模块的 perldoc,这是包含 javascript 文件的推荐方法:

print $q->start_html(-title=>'The Riddle of the Sphinx',
                 -script=>[
                           { -type => 'text/javascript',
                             -src      => '/javascript/utilities10.js'
                           },
                           { -type => 'text/javascript',
                             -src      => '/javascript/utilities11.js'
                           },
                           { -type => 'text/jscript',
                             -src      => '/javascript/utilities12.js'
                           },
                           { -type => 'text/ecmascript',
                             -src      => '/javascript/utilities219.js'
                           }
                        ]
                    );

$q 将保存一个 CGI 对象,并且还应该用于构造 HTML 的其余部分。这应该会大大提高其有效的机会。您还需要验证“/test.js”是获取 javascript 文件的正确 URL,并通过检查您的服务器日志来确认它已返回给浏览器。您还可以在 Firebug 中检查您的浏览器正在请求和接收它。

最后,虽然 CGI 在 10 或 12 年前非常流行,但今天有许多更现代的方法可以用 perl 开发 Web 应用程序。例如,检查 cpan 的CGI::ApplicationDancer。使用 Template::Toolkit 之类的东西也可以让你的生活更轻松。

于 2012-07-10T13:59:28.467 回答