我尝试下载excel文件并在将其发送给用户之前进行检查。当我在var response - oReq.response
上设置断点时,我看到oReq.response为空。当我检查我的网络选项卡时,我看到响应不是null,而是它是预期的excel文件。为什么excel文件没有通过回调?
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();
响应标题:
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?=