繁体   English   中英

将Ajax异步应用于以HTML设计的表(.tmpl文件),并通过Perl检索数据(.cgi文件)

[英]Applying Ajax asynchronously upon a table designed in HTML (.tmpl file) and retrieves data through Perl (.cgi file)

我有2个单独的链接文件->(1).cgi(用于从URL检索数据的Perl文件),以及(2).tmpl(已构造表的HTML模板)。 两者都通过HTML :: Template链接了。

我需要异步刷新表行的内容,例如每20秒刷新一次。 同样,我在.tmpl文件中创建了需要刷新的各种div ID。

以下是代码:1. Perl代码(.cgi文件,检索表的内容):

#!/Dwimperl/perl/bin/perl

use strict;
use warnings;
use LWP::Simple;
use HTML::Table;
use HTML::TableContentParser;
use HTML::Template;
use CGI;

print "Content-type: text/html\n\n";
my $template = HTML::Template->new(filename => 'tryin.tmpl');
my $cgi = new CGI;
use CGI::Carp qw(fatalsToBrowser);
#1======================================================
#-------------------------------------------------------
#Fetching AIRTEL HVP1
#-------------------------------------------------------
my $URL1= "http://****/server1";
my $content1 = get($URL1);
my $str12;
my $count13;
my $count14;
my $str15;
my $str16; # GHANA TIME
#2------------------------------------------------------
# FOR IP #
#-------------------------------------------------------
my $value1=0;
my $value2=0;
if ($content1 =~ m/IP/g) {$value1=pos($content1);}
if ($content1=~m/Blocked/g) {$value2=pos($content1);}
$str12=substr($content1,$value1,$value2-$value1);
$str12=~s/[^\d.-]//g;
#print($str12);
$template->param(A12=>$str12);
#3------------------------------------------------------
# FOR INCALL #
#-------------------------------------------------------
$count13=0;
while ($content1 =~ m/bgcolor='green'/g) 
{$count13=$count13+1;}
$count13=$count13-1;
#print($count13);
$template->param(A13=>$count13);
#4------------------------------------------------------
# FOR OBD #
#-------------------------------------------------------
$count14=0;
while ($content1 =~ m/bgcolor='blue'/g) 
{$count14=$count14+1;}
$count14=$count14-1;
#print($count14);
$template->param(A14=>$count14);
#5------------------------------------------------------
# FOR BUSY CIRCUIT #
#------------------------------------------------------- 
$value1=0;
$value2=0;
if ($content1 =~ m/Busy Cir./g) {$value1=pos($content1);}
if ($content1=~m/OBD/g) {$value2=pos($content1);}
$str15=substr($content1,$value1,$value2-$value1);
$str15=~s/[^\d.-]//g;
#print($str15);
$template->param(A15=>$str15);
#6------------------------------------------------------
# FOR THE DISPALY OF LOCAL TIME
#-------------------------------------------------------
$content1 = get($URL1);
$value1=0;
$value2=0;
if ($content1=~m/Current time/g) {$value1=pos($content1);}
if ($content1=~m/Circuits/g) {$value2=pos($content1);}
$str16=substr($content1,$value1,$value2-$value1);
$str16=~s/[^\d..:._.-]//g;
#print($str16);
$template->param(TIME=>$str16);
#2=====================================================
#------------------------------------------------------
#Fetching AIRTEL HVP2
#------------------------------------------------------
my $URL2= "http://****/server2";
my $content2 = get($URL2);
my $str22;
my $count23;
my $count24;
my $str25;
#2-----------------------------------------------------
# FOR IP #
#------------------------------------------------------
$value1=0;
$value2=0;
if ($content2 =~ m/IP/g) {$value1=pos($content2);}
if ($content2=~m/Blocked/g) {$value2=pos($content2);}
$str22=substr($content2,$value1,$value2-$value1);
$str22=~s/[^\d.-]//g;
#print($str22);
$template->param(A22=>$str22); 
#3-----------------------------------------------------
# FOR INCALL #
#------------------------------------------------------
$count23=0;
while ($content2 =~ m/bgcolor='green'/g) 
{$count23=$count23+1;}
$count23=$count23-1;
#print($count23);
$template->param(A23=>$count23);
#4-----------------------------------------------------
# FOR OBD #
#------------------------------------------------------
$count24=0;
while ($content2 =~ m/bgcolor='blue'/g) 
{$count24=$count24+1;}
$count24=$count24-1;
#print($count24);
$template->param(A24=>$count24);
#5----------------------------------------------------
# FOR BUSY CIRCUIT #
#-----------------------------------------------------
$value1=0;
$value2=0;
if ($content2 =~ m/Busy Cir./g) {$value1=pos($content2);}
if ($content2=~m/OBD/g) {$value2=pos($content2);}
$str25=substr($content2,$value1,$value2-$value1);
$str25=~s/[^\d.-]//g;
#print($str25);
$template->param(A25=>$str25);
#====================================================
print $template->output;
#====================================================
  1. HTML代码(由表和div ID组成的.tmpl文件):

    HVP使用情况报告

      <font color=#00124B> <center> <font size="7" face="calibri" color=#00124B><b>Ghana <img src="/ghanaa.jpg" width="80" height="40"></b></font> <br> <font size="6" face="calibri" color = #0033CC><b><TMPL_VAR NAME=TIME></b></font> <br><br> <table border="2" cellpadding="6" cellspacing ="4" > <tr bgcolor=#00248E> <th><font face="calibri" size="7" color=#BFCFFE>Client</font></th> <th><font face="calibri" size="7" color=#BFCFFE>HVP</font></th> <th><font face="calibri" size="7" color=#BFCFFE>IP</font></th> <th><font face="calibri" size="7" color=#BFCFFE>Incall</font></th> <th><font face="calibri" size="7" color=#BFCFFE>OBD</font></th> <th><font face="calibri" size="7" color=#BFCFFE>Busy Cir.</font></th></font> </tr> <tr> <td align ="center"><font size="6" face="calibri" color=#00124B><img src="/airtel.jpg" width="100" height="56"></font></td> <td align ="center" bgcolor=#BFCFFE><font size="7" face="calibri" color=#00124B>VP1</font></td> <td ialign ="center" bgcolor=#BFCFFE><font size="7" face="calibri" color=#00124B><TMPL_VAR NAME=A12></font></td> <div id="A1"> <td align ="center" bgcolor=#BFCFFE><font size="7" face="calibri" color=#00124B><b><TMPL_VAR NAME=A13></b></font></td> <td align ="center" bgcolor=#BFCFFE><font size="7" face="calibri" color=#00124B><b><TMPL_VAR NAME=A14></b></font></td> <td align ="center" bgcolor=#BFCFFE><font size="7" face="calibri" color=#00124B><b><TMPL_VAR NAME=A15></b></font></td> </div> </tr> <tr> <td align ="center"><font size="6" face="calibri" color=#00124B><img src="/airtel.jpg" width="100" height="56"></font></td> <td align ="center" bgcolor=#809FFE><font size="7" face="calibri" color=#00124B>VP2</font></td> <td align ="center" bgcolor=#809FFE><font size="7" face="calibri" color=#00124B><tmpl_var name=A22></font></td> <div id="A2"> <td align ="center" bgcolor=#809FFE><font size="7" face="calibri" color=#00124B><b><tmpl_var name=A23></b></font></td> <td align ="center" bgcolor=#809FFE><font size="7" face="calibri" color=#00124B><b><tmpl_var name=A24></b></font></td> <td align ="center" bgcolor=#809FFE><font size="7" face="calibri" color=#00124B><b><tmpl_var name=A25></b></font></td> </div> </tr> </table> </center> </font> 

请协助我在上述文件上应用ajax及其功能。 谢谢

您将需要使用客户端javascript刷新行。

  • 首先看一下jQuery,它提供了简化ajax请求和DOM操作的功能。
  • 将单独的CGI文件用于ajax路由并将数据访问代码保存在共享的perl模块中通常更容易。 这将清楚地区分商务逻辑和两种观点

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM