我使用jquery jtable发送ajax从服务器获取excel文件但是Response :: download不起作用
$writer = (new WriterFactory())->createWriter(new Excel5(public_path().'/file/myExport.xls'));
$phpExcel = $writer->convert($workbook);
$writer->write($phpExcel);
Response::download(public_path().'\file\myExport.xls');
答案 0 :(得分:2)
Javascript无法访问文件系统,您无法使用ajax下载文件。尝试使用指向该文件的iframe下载它。
<iframe id="downloadFrame" style="display:none"/>
需要下载时,请使用以下脚本:
var iframe = document.getElementById("downloadFrame");
iframe.src = "yourpathtofile";
如果您使用jQuery,可以尝试:
$("#downloadFrame").attr("src","yourpathtofile");
另一种解决方案是使用window.open
window.open("pathtoyourfle");