Hi:
I'm writing a web-app Ajax and perl. Outputs of the server are either in
JSON or CSV.
A lot of my code are in form of following
sub output_JSON
{
my ($cgi, $ref_data) = @_; # CGI.pm object and reference to
data
structure
print $cgi->header (-type=>'text/json');
print json_encode $ref_data # convert data to
JSON
format and send it
}
sub output_Excel
{
my ($cgi, $ref_data) = @_;
print $cgi->header (-type => 'application/vnd.xls');
print to_csv $ref_data
}
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've tried the following gimmicks (which didn't work of course)
a) close and re-open STDOUT
b) Add "Connection: close" to the HTTP headers
c) Adding "Content-Length" to the HTTP headers
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"
Sorry for the repeated OT post.
Regards,
Ludwig
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph