再见,请扩展你的ajax调用,它只需要下载你需要的数据就可以强制下载文件。实际上,ajax调用将数据从远程浏览器传输到本地浏览器,因此您只需要一种方法,让浏览器将所有内容放入一个文件中并开始本地下载(从浏览器到下载文件夹)
$("#get_extract").on("click", function() {
$.ajax({
method: "POST",
url: "/back-office/extraction",
data: {
begin_date: $("#begin_date").val(),
end_date: $("#end_date").val()
},
success: function(csv_content) {
let filename = 'data.csv';
let csvFile = new Blob([csv_content], {type: "text/csv"});
let downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
document.body.appendChild(downloadLink);
downloadLink.click();
}
})