一. thinkphp5 导出 excel 没有下载 ,而是返回的二进制流,前端将二进制流转换位 excel下载
$.ajax({
url: "{:url('team/outExcel')}",
type: 'POST',
data: {data: data},
xhrFields: {
responseType: 'blob'
},
success: function (response, textStatus, jqXHR) {
var disposition = jqXHR.getResponseHeader('Content-Disposition');
var matches = /filename[^;=\n]*=(["'])(.+)\1/.exec(disposition);
if (matches && matches.length > 2) {
var fileName = decodeURIComponent(matches[2]);
var link = document.createElement('a');
link.href = window.URL.createObjectURL(response);
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
console.error('Filename not found in Content-Disposition header');
}
},
error: function (xhr, status, error) {
var response = JSON.parse(xhr.responseText);
layer.msg(response.msg, {icon: response.icon, time: 1000}, function () {
window.location.reload();
});
}
});