Hi:
Found out the cause of my problem, but having the correct HTTP
response
headers won't make the browser open an Excel even if the Content-Type is set to
"application/vnd.ms-excel" or "text/csv". I guess Ajax just ignore those
headers.
Thanks Zak for introducing the framework. I'll look at them when I
have a complicated web based Perl project :-)
Regards,
Ludwig
> Message: 5
> Date: Tue, 29 Jun 2010 10:34:34 +0800
> From: "Zak B. Elep" <[email protected]>
> Subject: Re: [plug] Help in Ajax/CGI programming in Perl(OT)
> To: "Philippine Linux Users' Group (PLUG) Technical Discussion List"
> <[email protected]>
> Message-ID:
> <[email protected]>
> Content-Type: text/plain; charset=UTF-8
>
> Hi!
>
> On Mon, Jun 28, 2010 at 4:26 PM, Ludwig Isaac Lim <[email protected]> wrote:
> > Hi:
> >
> > ? ? I'm writing a web-app Ajax and perl. Outputs of the server are either
in
> > JSON or CSV.
>
> [...]
>
> > ? ? ?My problem is if output_JSON is called twice (or output_Excel is
called
> > after an output_JSON), the CGI headers are included in the data (not
>headers)
> > send back to client, thus making the data un-parsable or corrupt. I was
> > able
>to
> > verify that the HTTP headers got included in data via means Firebug plugin
>for
> > firefox.
> >
>
> [...]
>
> >
> > ? ?I'm running the whole stuff on Perl 5.8.0, and on an antiquated version
>of
> > Apache (1.x series), and HP-UX. Any ideas? I already spend a lot of time
> > googling on "CGI" and "HTTP"
>
> If not because you're on 5.8.0, I'd suggest using Mojolicious,[0] as
> it has native JSON output (and also WriteExcel support, via my shiny
> new MojoX::Renderer::WriteExcel[1] which I'm still improving on ;)
>
> [0] http://mojolicious.org
> [1] http://search.cpan.org/dist/MojoX-Renderer-WriteExcel/
>
> As you're on 5.8.0, I presume your $CGI::VERSION is 2.81 (unless you
> upgraded it.) Checking both perldelta and CGI.pm's Changes,[2] there
> are a few behavior changes in $cgi->header() so you might want to look
> at the list, and possibly upgrade.
>
> [2] http://cpansearch.perl.org/src/LDS/CGI.pm-3.49/Changes
>
> Anyway, looking at your subs above, I see that you print your data to
> different filehandles, while your $cgi->header() call prints to the
> default filehandle (presumably STDOUT). Maybe that's where your
> problem is?
>
> Or maybe, just maybe, those filehandles after print are actually
> functions :P If that's the case, then you're calling them wrong,
> because print() will treat those as filehandles (e.g. print()'s first
> form,
>
> print FILEHANDLE LIST
>
> in `perldoc -f print'.) You should be calling them like
>
> print json_encode($ref_data);
>
> Thinking about it more, I also see your output_* functions repeat a
> basic function: set a header then print data. I think a better
> approach would be to have a hash that collects these info (headers and
> data) then pass this hash to a generic renderer function that does all
> the output for you in one section of code. Come to think of it, this
> is exactly the way Mojolicious does this (via MojoX::Renderer).
>
> --
> Zak B. Elep || zakame.net
> 1486 7957 454D E529 E4F1 F75E 5787 B1FD FA53 851D
>
>
> ------------------------------
>
> _________________________________________________
> Philippine Linux Users' Group (PLUG) Mailing List
> http://lists.linux.org.ph/mailman/listinfo/plug
> Searchable Archives: http://archives.free.net.ph
>
> End of PLUG Digest, Vol 63, Issue 22
> ************************************
>
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph