I attempting to download an excel file and check it before sending it on to the user. When I set a breakpoint on var response - oReq.response
, I see that oReq.response is null. When I check my network tab, I see that the response is not null rather it is the excel file as expected. Why doesn't the excel file come through to the callback?
var oReq = new XMLHttpRequest();
oReq.open("GET", service, true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
var response = oReq.response;
if (response === parseInt(response, 10)) {
alert("That query had no results");
$("#dialog").dialog("close");
}
else {
var blob = new Blob([response], { type: "application/vnd.ms-excel" });
var objectUrl = URL.createObjectURL(blob);
window.location = objectUrl;
//saveAs(blob, 'Ad_Hoc_Results.xls');
$("#dialog").dialog("close");
}
};
oReq.send();
Response Headers:
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Disposition:attachment; filename=AdHocReport.xls
Content-Length:6656
Content-Type:application/vnd.ms-excel
Date:Mon, 20 Jul 2015 19:56:50 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcRGV2XE5KVEFcTGFuZUNsb3N1cmVBcGlcYXBpXHJlcG9ydFxHZXRBZEhvY1F1ZXJ5UmVwb3J0?=