0

基本上我想在执行程序时将数据从 fetch_javaScript 函数传递到 database_fetch 我得到以下错误TypeError: div is null

有时我能够传递数据 database_fetch 函数,但无法找到准备。

    use strict;
    use CGI;
    use DBI;
    use Data::Dumper;
    require ("/usr/local/lib/perl5/site_perl/5.8.8/Class/Accessor.pm");
    require ("/usr/local/lib/perl5/site_perl/5.8.8/CGI/Ajax.pm");

    my $p = new CGI qw(header start_html end_html h1 script link);
    my $ajax = new CGI::Ajax( 'fetch_javaScript' => my $database_fetch );

    $p->header(-charset=>'US-ASCII');
    print $ajax->build_html($p,\&generateHTML);

sub generateHTML
        {
        my %lable_fund=("Select"=>"Select",
                        "PMF"=>"PMF",
                        "PRAMERICA"=>"PRAMERICA",
                        "DHL"=>"DHL",
                        "EMF"=>"Edelweiss MF"
                        );
         my %lable_agent=("Select"=>"Select",
                        "Gyanesh"=>"Gyanesh",
                        "Satish"=>"Satish",
                        "Sailesh"=>"Sailesh",
                        "ArchanaMuluguru"=>"Archana",
                        "Santosh"=>"Santosh",
                        "Priyanka"=>"Priyanka"
                        );

        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',

                     -text=>'black',
                     -bgcolor=>'Gray',
                     -lang => "javascript",
                     -script => [{ -type => 'image/gif',
                                   -src => $jquery },
                                 { -type => 'text/javascript',
                                   -src => $datepicker },
                                ],
                     );

        print "Fund Name      ",$p->popup_menu(-name=>'fund',
                                -id => 'fund1',
                                -values  =>['Select','PMF','PRAMERICA','JM','DHL','EMF'],
                                -default => 'Select',
                                -multiple=>'true',
                                -labels  =>  \%lable_fund),"\n";

        print "<P>";
        print "Agent Name     ",$p->popup_menu(-name=>'agent',
                                -id => 'agent1',
                                -values=>['Select','Gyanesh','Satish','Sailesh','ArchanaMuluguru','Santosh','Afreen','Salman','Balaji','Priyanka'],
                                -default => 'Select',
                                -multiple=>'true',
                                -labels  => \%lable_fund),"\n";


 print "<P>";

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


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


        print $p->button(-name=>'Submit',-value=>'Submit',-onclick=>"fetch_javaScript(['fund1','agent1','demo3','demo4'],['id1','id2','id3','id4','id5'],'GET');return true;");
        print $p->end_html;
        }


$database_fetch =sub
                {

                my @Details;
#               my ($service_name,$agent_name,$call_start_time,$call_end_time);

                my $service_name = shift;
                my $agent_name=shift;
                my $call_start_time=shift;
                my $call_end_time=shift;
#               print "$service_name ","$agent_name","$call_start_time ","$call_end_time ";
                my $call_rec_file_name;

                my $DSN = q/dbi:ODBC:SQLSERVER/;
                my $uid = q/ivr/;
                my $pwd = q/ivr/;
                my $DRIVER = "Freetds";
                my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL";
                my $servernumber = 2;

                my $sql_fund=("select count '$service_name' from cti_services  where service_name='$service_name'");
                my $fund_count;
                my $sql_fund1 = $dbh->prepare($sql_fund);
                $sql_fund1->execute();
                $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);


 while (my @data = $sth->fetchrow_array())
                                {
                                @Details=@data;
                        return @Details;

                                }
                        }

}

提前致谢

4

1 回答 1

0

You are using $database_fetch before it is assigned. You should change the call to

my $ajax = CGI::Ajax->new(fetch_javaScript => \&database_fetch);

and the subroutine definition to

sub database_fetch {
  ...
}
于 2013-07-21T03:32:12.030 回答