ReferenceError:未定义fetch_javaScript

时间:2013-07-19 06:24:54

标签: ajax perl cgi

我已经在Perl中开发了网页,当我点击提交按钮时出现问题它会抛出错误 ReferenceError:fetch_javaScript 但我已经为fetch_javaScript定义了参考。

基本上我想要从fetch_javaScript传递捕获值到database_fetch。

#!/usr/bin/perl

use strict;
use CGI;
use DBI;
use Data::Dumper;
use Asterisk::AGI;
$agi = new Asterisk::AGI;
use CGI::AJAX;
$p = new CGI qw(header start_html end_html h1 script link);
$ajax = new CGI::Ajax( 'fetch_javaScript' => \&database_fetch );
$p->header( -charset => 'US-ASCII' );
print $ajax->build_html( $p, \&generateHTML );

sub generateHTML {
  my $datepicker = "datetimepicker.js";
  my $jquery     = "cal.gif";

  print $p->header();
  print $p->start_html( 'MFS CALL CENTER' );
  print $p->h3( 'MFS CALL RECORDINGS' );

  print $p->start_html(
    -title   => 'What we think we become',
    -meta    => { 'keywords' => 'Hard work' },
    -text    => 'black',
    -bgcolor => 'Gray',
    -lang    => "javascript",
    -script  => [ {
        -type => 'image/gif',
        -src  => $jquery
      }, {
        -type => 'text/javascript',
        -src  => $datepicker
      },
    ],
  );
  my %lable_fund = (
    "Select"    => "Select",
    "PMF"       => "PMF",
    "PRAMERICA" => "PRAMERICA",
    "DHL"       => "DHL",
  );

  my %lable_agent = (
    "Select"          => "Select",
    "Gyanesh"         => "Gyanesh",
    "Satish"          => "Satish",
    "Sailesh"         => "Sailesh",
    "ArchanaMuluguru" => "Archana"
  );
  print "Fund Name      ",
    $p->popup_menu(
    -name    => 'fund',
    -values  => [ 'Select', 'PMF', 'PRAMERICA', 'JM', 'DHL' ],
    -default => 'Select',
    -labels  => \%lable_fund
    ),
    "\n";

  print "<P>";
  print "Agent Name     ",
    $p->popup_menu(
    -name    => 'agent',
    -values  => [ 'Select', 'Gyanesh', 'Satish', 'Sailesh', 'ArchanaMuluguru' ],
    -default => 'Select',
    -labels  => \%lable_fund
    ),
    "\n";

  my $from_date = qq` <p>From Date</p> <input name="timestamp" id="demo3" type="text" size="25"><a href="javascript:NewCal('demo3','ddmmmyyyy',true,24)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>`;
  print $from_date;

  my $to_date = qq` <p>To Date</p> <input name="timestamp1" id="demo4" type="text" size="25"><a href="javascript:NewCal('demo4','ddmmmyyyy',true,24)"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>`;
  print $to_date;

  print "<P>";

  print $p->td(
    $p->submit(
      -name    => 'Submit',
      -value   => 'Submit',
      -src     => 'tesl.pl',
      -onclick => "fetch_javaScript(['fund'],['agent'],['timestamp'],['timestamp'])"
    ) );

  print $p->end_html;
}

sub database_fetch {

  my ( $service_name, $agent_name, $call_start_time, $call_end_time ) = @_;

  #               print "service_name=$service_name ","agent_name=$agent_name","call_start_tim=$call_start_time ","call_end_time=$call_end_time= ";
  my $call_rec_file_name;
  my $sql_fund = ( "select count(?) from cti_services  where service_name=?" );
  my $fund_count;
  my $sql_fund1 = $dbh->prepare( $sql_fund );
  $sql_fund1->execute( $service_name, $service_name );
  $sql_fund1->bind_columns( \$fund_count );
  $sql_fund1->fetch;

  my $sql_agent = ( "select count(agent_name) from cti_agents where agent_name=?" );
  my $agent_count;
  my $sql_agent1 = $dbh->prepare( $sql_agent );
  $sql_agent1->execute( $agent_name );
  $sql_agent1->bind_columns( \$agent_count );
  $sql_agent1->fetch;

  if ( $fund_count == 1 && $agent_count == 1 ) {
    my $sql = "select top(10) service_name,agent_name,call_rec_file_name,call_start_time,call_end_time from cti_agents join  cti_call_master on (agent_name = call_agent_name) join cti_services on (call_service_id = service_id) where agent_name = 'Sailesh' and call_rec_file_name is not null";
    my $sth = $dbh->prepare( $sql );
    $sth->execute();
    print "Service Name", " Agent Name", "    Call Start Time     ", "      Call End Time     ", "         Sound File ", "\n";
    while ( my @data = $sth->fetchrow_array() ) {
      my ( $service_name, $agent_name, $call_rec_file_name, $call_start_time, $call_end_time ) = @data;
      print '<p>"$service_name ","    $agent_name ","     $call_start_time ","  $call_end_time ","  $call_rec_file_name  "</p>';
    }
  }
}

提前致谢

0 个答案:

没有答案