boy*_*od3 5 ajax jquery spring-mvc
嗨,我想使用spring mvc ajax调用下载XLX文件。以下是我对服务器的ajax调用。
$.ajax({
type : 'GET',
url : 'downloadExcel',
beforeSend : function() {
startPreloader();
},
complete: function(){
stopPreloader();
},
success : function(response){
console.log(response);
var blob = new Blob([response], { type: 'application/vnd.ms-excel' });
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = downloadUrl;
a.download = "downloadFile.xlsx";
document.body.appendChild(a);
a.click();
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的服务器代码
@RequestMapping(value = "/downloadExcel", method = RequestMethod.GET)
@ResponseBody
public List<LicenceType> downloadExcel() {
return licenceTypeService.findAllLicenceType();
}
Run Code Online (Sandbox Code Playgroud)
我的代码实际上下载了excel文件,但是在excel表格上它显示为
[Object][Object]
我知道已经过去了快一年了,但它对我有用:
var blob = new Blob([response], { type: 'data:application/vnd.ms-excel' });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14920 次 |
| 最近记录: |