Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
严格使用CGI::AJAX_Ajax_Perl - Fatal编程技术网

严格使用CGI::AJAX

严格使用CGI::AJAX,ajax,perl,Ajax,Perl,我在表中有一组用于更新密码的代码,在这里我使用CGI::AJAX模块更新密码,并在相应的执行时获得弹出屏幕。在我的应用程序中使用该代码时,它正在正确执行,但我没有得到输出(意味着当JavaScript函数未更新到表中时,不会调用Perl子例程来获取use.password) #!/usr/bin/perl -w use strict; use CGI; use DBI; use Data::Dumper; my $p = new CGI qw(header start_html end_html

我在表中有一组用于更新密码的代码,在这里我使用CGI::AJAX模块更新密码,并在相应的执行时获得弹出屏幕。在我的应用程序中使用该代码时,它正在正确执行,但我没有得到输出(意味着当JavaScript函数未更新到表中时,不会调用Perl子例程来获取use.password)

#!/usr/bin/perl -w
use strict;
use CGI;
use DBI;
use Data::Dumper;
my $p = new CGI qw(header start_html end_html h1 script link);
use Class::Accessor;
use CGI::Ajax;
my $create_newuser;
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);

print $ajax->build_html($p,\&Show_html,{-charset=>'UTF-8', -expires=>'-1d'});

sub Show_html
        {
        my $html = <<EOHTML;
<html>
<body bgcolor="#D2B9D3">
<IMG src="karvy.jpg" ALT="image">
<form name='myForm'>
<center><table><tr><td>
<div style="width:400px;height:250px;border:3px solid black;">
<center><h4>Create New Password's</h4>

<p>&nbsp User Name</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT TYPE="text" NAME="user" id = "user" size = "15" maxlength = "15" tabindex = "1"/></p>
<p>&nbsp Password:</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<INPUT TYPE=PASSWORD NAME="newpassword" id = "newpassword" size = "15" maxlength = "15" tabindex = "1"/></p>
<p>&nbsp Re-Password:</b>&nbsp&nbsp&nbsp<INPUT TYPE=PASSWORD NAME="repassword" id = "repassword" size = "15" maxlength = "15" tabindex = "1"/></p>
<input type="submit" id="val" value="Submit" align="middle"  method="GET" onclick="fetch_javaScript(['user','newpassword','repassword']);"/><INPUT TYPE="reset" name = "Reset" value = "Reset"/>
<p>Main Menu <A HREF = login.pl>click here</A>
</center>
</div>
</td></tr></table></center>
</form>
</body>
</html>

EOHTML

return $html;
        }


$create_newuser =sub
                {

                my @input = $p->params('args');
                my $user=$input[0];
                my $password=$input[1];
                my $repassword=$input[2];

                my $DSN = q/dbi:ODBC:SQLSERVER/;
                my $uid = q/123/;
                my $pwd = q/123/;
                my $DRIVER = "Freetds";
                my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL";
                if ($user ne '')
                        {
                        if($password eq $repassword)
                                {
                                        my $sth=$dbh->do("insert into rpt_account_information (user_id,username,password,user_status,is_admin) values(2,'".$user."','".$password."',1,1)");
                                        my $value=$sth;
                                        print $value,"\n";
                                        if($value == 1)
                                        {
                                                print 'Your pass has benn changed.<a href="login.pl">Return</a> to the main page';
                                        }
                                }
                        else
                                {
                                        print "<script>alert('Password and Re-Password does not match')</script>";
                                }
                        }

                else
                        {
                                print "<script>alert('Please Enter the User Name')</script>";

                        }

                }
!/usr/bin/perl-w
严格使用;
使用CGI;
使用DBI;
使用数据::转储程序;
my$p=新CGI qw(标题开始\ html结束\ html h1脚本链接);
使用Class::Accessor;
使用CGI::Ajax;
我的$create_newuser;
my$ajax=newcgi::ajax('fetch\u javaScript'=>$create\u newuser);
打印$ajax->build\uhtml($p,\&Show\uhtml,{-charset=>'UTF-8',-expires=>'-1d'});
子显示
{
我的$html=
当您创建一个新的
CGI::Ajax
对象时,
$create\u newuser
变量仍然是
undef
。直到很久以后,您才为它分配一个coderef

您可以在创建
CGI::Ajax
之前分配
$create\u newuser

my $create_newuser =sub { ... };
my $ajax = new CGI::Ajax('fetch_javaScript' => $create_newuser);
...;
或者使用一个普通的命名子例程并传递一个coderef

my $ajax = new CGI::Ajax('fetch_javaScript' => \&create_newuser);
...;
sub create_newuser { ... }

除了这个主要错误之外,您的脚本还有很多问题

您应该
使用strict
而不是
-w
选项

仅出于调试目的,
使用CGI::Carp'fatalsToBrowser'
有时甚至使用
警告tobrowser
也会非常有用。否则,必须密切关注错误日志

my$p=new CGI qw(header start\u html end\u html h1脚本链接)
没有任何意义。
my$p=CGI->new
应该足够了

use Class::Accessor
在这里似乎有点随机

Show\u HTML
中的HTML是粗心的。首先,您的herdocs允许变量插值和转义码–它具有双引号字符串的语义。大多数情况下,您不希望这样。启动一个herdoc,如
do(“插入到…值('$foo')”)
使用
$sth->do('INSERT-in…VALUES(?),$foo)

print…
–您的Ajax处理程序不应该打印输出,而应该
返回一个HTML字符串,然后在JS函数指定的位置连接到DOM中

use HTML::Entities;

sub create_newuser {
  my ($user, $password, $repassword) = $p->params('args');
  my ($e_user, $e_password) = map { encode_entities($_) } $user, $password;
  # DON'T DO THIS, it is a joke
  return "Hello <em>$e_user</em>, your password <code>$e_password</code> has been successfully transmitted in cleartext!";
}
在你的JS中:

fetch_javaScript(['user','newpassword','repassword'], ['answer-element'], 'GET');
当您的HTML文档某处有一个

my$ajax=new CGI::ajax('fetch\u javaScript'=>\&create\u newuser);…;sub-create\u newuser{…}当我使用此代码时出现一些问题,我没有得到任何错误,表中没有发生更新
fetch_javaScript(['user','newpassword','repassword'], ['answer-element'], 'GET');