function workDownLoad(workID) {
var fileName = "";
var status = false;
$.ajax({
type: "Post",
url: "/Common/GetWorkOrPlayName",
datatype: "json",
data: {
id: workID,
type: 0
},
async: false,
success: function (data) {
if (data.status == 0) {
fileName = data.WorkName;
status = true;
} else {
status = false;
}
},
error: function () { }
});
if (!status) {
return;
}
var url = "/Common/WorkDownLoad/" + workID;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);//get请求,请求地址,是否异步
xhr.responseType = "blob"; // 返回类型blob
xhr.onload = function (data, textStatus, request) {// 请求完成处理函数
if (this.status === 200) {
var blob = this.response;// 获取返回值
var a = document.createElement('a');
//var name = request.getResponseHeader('Content-Disposition');
a.download = fileName;
a.href = window.URL.createObjectURL(blob);
a.click();
}
};
// 发送ajax请求
xhr.send();
}