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();
}