punkish has asked for the wisdom of the Perl Monks concerning the following question:
I wrote a reasonably complicated HTML:Template-based web application that works fine. Now, I want to insert some XMLHttpRequest functionality. I've got the skeleton code working, however, I can't for the life of me figure out how to merge it with HTML::Template. Here is the pseudo-flow of the application --
### in my code my $foo = $cgi->param('foo'); # do a bunch of things with $foo, # get data out of SQLite, # prepare html output, print "Content-Type: text/html\n\n", $template->output; ### in my template <TMPL_LOOP FOO> <TMPL_VAR BAR><br> </TMPL_LOOP>
But, now I've added the XMLHttpRequest code to the template so 'foo' is sent to the server in background, so to say. However, I can't output the entire $template anymore... I have to output only the resulting recordset, receive it back at the client's end, process it and output it using innerHTML to create the same pretty output that I was getting with TMPL_LOOP. The best I can figure is --
### in my code my $foo = $cgi->param('foo'); # figure out if XMLHttpRequest if ($foo) { # do a bunch of things with $foo, # get data out of SQLite, # prepare XMLHttpRequest output print "Content-Type: text/html\n\n", $output; # for all other normal cgi requests } else { # grab cgi params, # do a bunch of things with them, # get data out of SQLite, # prepare html output, print "Content-Type: text/html\n\n", $template->output; } ### in my template, # document.getElementById("output").innerHTML = output; <div id="output"></div>
Well, isn't that terrible? I've just gone and messed up my neat H::T based View and Controller separation. Is there a cleaner, better, more satisfying method?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: integrating XMLHttpRequest and HTML::Template
by mpeters (Chaplain) on Jun 03, 2005 at 14:48 UTC | |
|
Re: integrating XMLHttpRequest and HTML::Template
by cees (Curate) on Jun 03, 2005 at 14:26 UTC | |
by punkish (Priest) on Jun 03, 2005 at 14:30 UTC | |
|
Re: integrating XMLHttpRequest and HTML::Template
by cfreak (Chaplain) on Jun 03, 2005 at 14:46 UTC |