接口返回的数据是直接的二进制文件,使用ajax没有办法直接进行下载,所以使用form表单的submit向接口发请求标签:body,文件,Popup,form,url,formdata,input,下载 From: https://www.cnblogs.com/1521681359qqcom/p/16709801.html
function formDownload(url,data){
var form = $("<form method='post' style='display:none;'></form>"),
input;
if(url == ""){
Popup.closeDragBox();
Popup.msg({message: '请配置下载地址!', type: 'info', duration: 3000});
return
}
form.attr({"action": url});
$.each(data, function (key, value) {
input = $("<input type='hidden'>");
input.attr({"name": key});
input.val(value);
form.append(input);
});
form.appendTo(document.body);
try{
form.submit();
}catch(e){
Popup.msg({message:e.toString(), type: 'info', duration: 3000});
}
document.body.removeChild(form[0]);
Popup.closeDragBox();
}