首页 文章

在包含jquery-1.11.3.min.js之后,浏览器不会对perl CGI重定向/打印html做出反应/更新

提问于
浏览
0

我正在尝试使用perl和CGI实现基本的用户授权系统 . 在HTML登录页面的 Headers 中包含 jQuery 1.11.13.min.js之后,浏览器(firefox和safari)不会对CGI重定向(成功登录到新页面)或甚至是简单的打印HTML做出反应 . 浏览器的内容区域和URL文本框保持不变,因为CGI脚本从未执行过 . 但我知道脚本已经执行了 .

Here is a summary of the system:
首先向用户显示一个HTML登录页面( login_page.html ),其中包含一个带有'username'和'password'字段的基本登录表单,表单操作是使用POST调用的cgi脚本( verify.cgi ) .

此脚本检查凭据是否正常,并且 redirects 指向新的CGI脚本( welcome.cgi ),该脚本以HTML格式打印基本欢迎消息,或者只打印基本的html消息,然后(此帖子中包含所有三个文件) .

但是,重定向到欢迎(CGI)页面后出现问题 . welcome.cgi 脚本被成功调用,因为我在服务器的文件中打印了一条消息 . BUT 浏览器的url-address框(firefox 41.0.2和safari 6.2.4)没有更新, http://..../verify.cgi url仍然存在 . 此外,浏览器显示登录页面html,并且不会将其内容区域更新为 verify.cgi / welcome.cgi 脚本输出的欢迎或失败登录消息html .

在我的登录页面的 Headers 中包含标准的jQuery js文件(http://code.jquery.com/jquery-1.11.3.min.js)之后出现问题(在html中) .

任何人都可以帮我找出我做错了什么以及如何解决它?

请不要问我为什么要包含jQuery . 而且我更喜欢坚持使用perl而不是其他任何东西 .

关于代码和设计的一般评论表示欢迎 .

非常感谢

以下是最基本形式的三个文件:

  • login_page.html
<!doctype html>
<html>
<head>
<!-- this one creates a problem with CGI redirect -->
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- this one does not seem to create any problem -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>
<body>
<form action="/bin/verify.cgi" method="post" name="login_form">
 <input type="text" name="username" id="username">
<input type="password" name="password" id="password">
<input type="submit" value=" Log In " name="login_button"/> </form> </body> </html>
  • verify.cgi
#!/usr/bin/env perl

use strict;
use warnings;
use CGI::Carp;
use CGI::Session;
use CGI;

my $cgi = CGI->new;

my $username = $cgi->param("username");
my $password = $cgi->param("password");

if( defined($username) &&
    defined($password) &&
    ($username eq 'test') &&
    ($password eq 'test')
){
    # successful login
    my $session = CGI::Session->new(
        "driver:File",
        undef,
        {Directory=>'/tmp'}
    );
    my $sid = $session->id();
    $session->param('username', $username);
    # setup the cookie to the session
    my $cookie = $cgi->cookie(
        -name  => 'CGISESSID',
        -value => $sid
    );
    $session->save_param();
    $session->flush();
    # move on to the next page and place the cookie in the headers
    # the script in the -location is EXECUTED OK - so redirect works
    # however browser does not update URL textbox nor its content page:
    print $cgi->redirect(
            -cookie   => $cookie,
            -url => 'http://c3.myartsonline.com/bin/welcome.cgi'
    );
    # even with this it does not work
    # print $cgi->header() . "<html><body>welcome, login successful</body></html>";

} else {
    # login failed
    # this I can not see in the browser either
    print $cgi->header() . '<html><body>login failed</body></html>';
}
1;
__END__
  • welcome.cgi
#!/usr/bin/env perl

use strict;
use warnings;
use CGI;
use CGI::Session;
my $cgi = CGI->new;

my ($session, $username) = (undef) x 2;

my $sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
if( defined($sid) ){
    $session = CGI::Session->new(undef, $sid, {Directory=>'/tmp'});
    if( defined($session) ){
        $username = $session->param('username')
    }
}
if( defined($username) ){
    print $cgi->header() . "<html><body>welcome user '$username', login successful</body></html>";
    open(OUT, ">hello");
    print OUT "weclome\n";
    close(OUT);
} else {
    print $cgi->header() . "<html><body>please login first</body></html>";
}
1;
__END__

1 回答

  • 0

    添加

    data-ajax="false"

    到文件内的表单定义(例如 <form data-ajax="false" ....>login_page.html

    解决了这个问题 . 现在,在执行CGI :: redirect()时,浏览器的URL文本框和内容区域会正确更新 .

    这会打破别的吗?谁知道 .

相关问题