Hello Mr. Mcnam,
I am wondering if anyone has tested sending a .xlsx attachment to a browser using Dojo 1.9. Using the
cgi.pl example and plain JavaScript AJAX Post gets the end result I am looking for. When attempting the same with Dojo no such luck. Could be my limited understanding of dojo, but Firebug console shows a response, in strange characters indicative of binary as I have recently learned. However it is not entering the if(resonse) statement. Am I missing something unique to Dojo with regards to the proper Content type?
I have tried several methods including adding and removing the bold line.
Here is the html code:<!DOCTYPE html>
<html>
<head>
<script src='../../lib/js_scripts/dojo-release-1.9.1/dojo/dojo.js'></script>
<script>
function callExcel()
{
require(["dojo/request","dojo/json"],function(request,json)
{
request.post("url", {
handleAs: "json",
//
headers: {"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"} }).then(function(response){
if(response)
{
alert("success");
//window.open("url","_blank"); //url (both in post and window.open) does exist , just cant put it out here.
}
});
});
}
</script>
</head>
<body>
<div id="MyDiv">This is not going well</div>
<button type="button" onClick="callExcel();">click_me</button>
</body>
</html>
Here is the cgi:use strict;
use warnings;
use Excel::Writer::XLSX;
use utf8;
my $cgi = CGI->new();
1;
my $workbook = '';
my $worksheet = '';
my $filename = "MasterList.xlsx";
print "Content-Disposition: attachment; filename=$filename\n";
print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n\n";
#print $cgi->header(-type=>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", -attachment=>$filename);
binmode(STDOUT);
$workbook = Excel::Writer::XLSX->new(\*STDOUT);
$worksheet = $workbook->add_worksheet();
# Set the column width for column 1
$worksheet->set_column(0, 0, 20);
# Create a format
my $format = $workbook->add_format();
$format->set_bold();
$format->set_size(15);
$format->set_color('blue');
# Write to the workbook
$worksheet->write(0, 0, "Hi Excel!", $format);
$workbook->close();
exit(0);