前后端分离,前端通过ng的$http传post到后端,后端返回responsetype为application/vns.ms-excel的数据,请问有什么方式才能让浏览器下载excel文件呢?
前后端分离,前端通过ng的$http传post到后端,后端返回responsetype为application/vns.ms-excel的数据,请问有什么方式才能让浏览器下载excel文件呢?
$http({
url: 'http://localhost:8083/console/devices/poi',
method: "POST",
data: {
"email": "官方邮箱"
},
headers: {
'Content-type': 'application/json'
},
responseType: 'arraybuffer'
}).then(function(data, status, headers, config) {
var blob = new Blob([data], { type: "application/vnd.ms-excel" });
var objectUrl = URL.createObjectURL(blob);
var aForExcel = $("<a><span class='forExcel'>下载excel</span></a>").attr("href", objectUrl);
$("body").append(aForExcel);
$(".forExcel").click();
aForExcel.remove();
})