$.ajax({
url:"/friends/exportFriendsNew",
type:"post",
async: true,
contentType : 'application/json',
cache: false,
xhrFields: { responseType: exportData.type==="preview"?"json":"blob" },
data:JSON.stringify(exportData),
success: function (data) {
//处理json数据
if(data&&data.result){
let infos = data.result;
if( infos == null){//页面数据为空时
$("#exportDataTxt").val("");
}else{
$("#exportDataTxt").val(infos)
}
$(".exportDivmessa").val(infos);
$(".exportDiv").show();
}else {
//处理后台返回的流数据
const blob = new Blob([data]);
const fileName = 'stats.xlsx';
const linkNode = document.createElement('a');
linkNode.download = fileName; //a标签的download属性规定下载文件的名称
linkNode.style.display = 'none';
linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
document.body.appendChild(linkNode);
linkNode.click(); //模拟在按钮上的一次鼠标单击
URL.revokeObjectURL(linkNode.href); // 释放URL 对象
document.body.removeChild(linkNode);
}
},
complete:function(XMLHttpRequest,textStatus){
if(callback&&typeof callback === 'function'){
callback()
}
}
});
网友评论