stonecolddevin has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: Got it working. See readmore for code.
#!C:/xampp/perl/bin/perl.exe -w use strict; use CGI; use CGI::Ajax; use Template; # for template toolkit support use CGI::Carp qw[fatalsToBrowser]; #DEBUG ONLY my $config = { INCLUDE_PATH => 'tt/', # or list ref }; my $cgi = CGI->new; my $pjx = CGI::Ajax->new( 'login' => \&do_login ); my $tt = Template->new($config); print $pjx->build_html($cgi, \&main_page); sub do_login { my $input = shift; # do something with $input my $output = $input . " was the input!"; return( $output ); } sub main_page { my $template = 'main.tt'; my $vars = { title =>'AJAX Test' }; my $output = ''; $tt->process($template, $vars, \$output) || die $tt->error(), "\n"; return $output; }
Hey gang.
This is probably something that's right in front of my face, but I'm attempting to get started on some AJAX using CGI::Ajax and Template (to handle HTML processing). The demo from the docs ran great, however my code is throwing this error:
malformed header from script. Bad header=<html><head><s +cript type="text: ajax.cgi
Not only that, but it's returning the HTML as text to the browser.
Here's my code:
#!C:/xampp/perl/bin/perl.exe -w use strict; use CGI; use CGI::Ajax; use Template; # for template toolkit support use CGI::Carp qw[fatalsToBrowser]; #DEBUG ONLY my $config = { INCLUDE_PATH => '/tt', # or list ref INTERPOLATE => 1, # expand "$var" in plain text POST_CHOMP => 1, # cleanup whitespace PRE_PROCESS => 'header', # prefix each template EVAL_PERL => 1, # evaluate Perl code blocks }; my $cgi = CGI->new; my $pjx = CGI::Ajax->new( 'login' => \&do_login ); my $tt = Template->new(); print $pjx->build_html($cgi, \&main_page); sub do_login { my $input = shift; # do something with $input my $output = $input . " was the input!"; return( $output ); } sub main_page { my $template = "main.tt"; return $tt->process($template, { title =>'AJAX Login'}) or die $tt-> +error; }
Any ideas? I'm thinking it's something to do with how build_html in CGI::Ajax tries to cope with process in T::T.
Thanks in advance!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: CGI::Ajax + Template::Toolkit Question
by chargrill (Parson) on Mar 07, 2007 at 04:16 UTC | |
Re: CGI::Ajax + Template::Toolkit Question
by randyk (Parson) on Mar 07, 2007 at 05:12 UTC | |
by stonecolddevin (Parson) on Mar 07, 2007 at 07:21 UTC | |
by randyk (Parson) on Mar 07, 2007 at 16:17 UTC | |
by stonecolddevin (Parson) on Mar 09, 2007 at 01:01 UTC | |
by randyk (Parson) on Mar 09, 2007 at 07:12 UTC |