返回 FileStreamResult,视图jQuery要怎么回调??

2019-01-03 01:33发布

如图,我返回的是FileStreamResult, 那视图用jQuery怎么回调呢?

2条回答
姐就是有狂的资本
2楼-- · 2019-01-03 01:49

function daochu() {

var xmlhttp=null;
if (window.XMLHttpRequest) {
// 针对非IE的标准浏览器
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
// 针对IE
try {
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
}
catch (e) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}


xmlhttp.open("POST", "@Url.Action("Daochu")", true);
xmlhttp.responseType = "blob";
xmlhttp.setRequestHeader("client_type", "DESKTOP_WEB");
xmlhttp.onload = function () {
if (this.status === 200) {
var blob = this.response;
downloadFile("订单导出数据.xls", blob);
} else {
layer.msg("导出失败");
}
};
xmlhttp.send();
}

function downloadFile(fileName, content) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(content, fileName);
} else {
var aLink = document.createElement('a');
var blob = new Blob([content], { type: 'application/vnd.ms-excel' });
var evt = document.createEvent("HTMLEvents");
evt.initEvent("click", false, false);//initEvent 不加后两个参数在FF下会报错, 感谢 Barret Lee 的反馈
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);
aLink.dispatchEvent(evt);
aLink.id = "alink";
aLink.click();
}
}

感谢@心存善念

查看更多
登录 后发表回答