帮忙看下perl cgi+Ajax+tt不能正确显示
本帖最后由 首天 于 2011-05-25 11:56 编辑
我想将三者结合起来使用,但是没有成功,朋友们帮我看看是哪里出错了,CGI+TT、CGI+Ajax均可以运行,CGI+Ajax+TT没有成功。
代码如下:
1,CGI程序,ia_ajax.pl
复制代码
2,TT模板,ia_ajax.tt
复制代码
3,浏览器显示:
4,服务器错误日志:
我想将三者结合起来使用,但是没有成功,朋友们帮我看看是哪里出错了,CGI+TT、CGI+Ajax均可以运行,CGI+Ajax+TT没有成功。
代码如下:
1,CGI程序,ia_ajax.pl
- #!/usr/bin/perl
- use warnings;
- use strict;
- use CGI;
- use CGI::Ajax;
- use Template;
- binmode STDOUT, ':utf8';
-
- my $tt_config = {
- INCLUDE_PATH => '/home/www/html/ia-template',
- PRE_CHOMP => 1,
- POST_CHOMP => 1,
- #INTERPOLATE => 1,
- EVAL_PERL => 1,
- START_TAG => quotemeta('<?'),
- END_TAG => quotemeta('?>'),
- };
-
- my $cgi = CGI->new;
- my $pjx = CGI::Ajax->new( 'login' => \&do_login );
- my $tt = Template->new($tt_config) || die "$Template::ERROR\n";
- print $pjx->build_html($cgi, \&main_page,{-charset=>'UTF-8', -expires=>'-1d'} );
-
- sub do_login {
- my $input = shift;
- my $output = $input . " was the input!";
- return( $output );
- }
-
- sub main_page {
- my $template = "ia_ajax.tt";
- return $tt->process($template, { title =>'AJAX Login'}) or die $tt->error;
- }
- #
- <html>
- <head>
- <title><? title ?></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <p>Please log in.</p>
- <p>Username: <input type="text" name="username" id="username" /></p>
- <p>Password: <input type="password" name="passwd" id="passwd" /></p>
- <p><input type="submit" name="login" value="login" onClick="login(['username'], ['passwd'], ['authenticated']);"/></p>
- </body>
- </html>
4,服务器错误日志:
作者: 首天 发布时间: 2011-05-25
mm?
作者: tmp 发布时间: 2011-05-25
错在了这里:
复制代码
应该改成这个的:
复制代码
模板里面还要加个div
复制代码
- sub main_page {
- my $template = "ia_ajax.tt";
- return $tt->process($template, { title =>'AJAX Login'}) or die $tt->error;
- }
- sub do_login {
- #my $input = shift;
- my ($username, $password) = @_;
- my $output = "$username and $password were the input!";
- return( $output );
- }
-
- sub main_page {
- my $template = "ia_ajax.tt";
- my $html;
- $tt->process($template, { title =>'AJAX Login'}, \$html) or die $tt->error;
- return $html;
- }
- <html>
- <head>
- <title><? title ?></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <p>Please log in.</p>
- <p>Username: <input type="text" name="username" id="username" /></p>
- <p>Password: <input type="password" name="passwd" id="passwd" /></p>
- <p><input type="submit" name="login" value="login" onClick="login(['username', 'passwd'], ['show']);"/></p>
-
- <div id="show"></div>
- </body>
- </html>
作者: tmp 发布时间: 2011-05-25
话说看你的日志貌似不是cgi
作者: tmp 发布时间: 2011-05-25