84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
前后端分离,前端通过ng的$http传post到后端,后端返回responsetype为application/vns.ms-excel的数据,请问有什么方式才能让浏览器下载excel文件呢?
// 创建a标签模拟下载 function exportExcel(params, filename) { return $http({ url: '/api/exportExcel', method: "POST", headers: { 'Content-type': 'application/json' }, params: params, responseType: 'arraybuffer' }).success(function (data) { var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); var objectUrl = URL.createObjectURL(blob); var a = document.createElement('a'); document.body.appendChild(a); a.setAttribute('style', 'display:none'); a.setAttribute('href', objectUrl); a.setAttribute('download', filename); a.click(); URL.revokeObjectURL(objectUrl); }); }