我使用 Laravel-Excel 将 eloquent 集合导出到 .xls 文件并将其存储在服务器中。而且,我返回 laravel 的下载响应类型,即response()->download($filePath)。
服务器代码的简单版本:
function getExportToFile($pId){
$data = array(
array('data1', 'data2'),
array('data3', 'data4')
);
Excel::create('strings', function($excel) use($data) {
$excel->sheet('Sheetname', function($sheet) use($data) {
$sheet->fromArray($data);
});
})->store('xls');
return response()->download(storage_path('exports/strings.xls'));}
客户端操作处理程序:
if(a == Actions.ExportTofile)
{
return new Promise( function(resolve,reject)
{
$.get('/project/export-to-file/' + p1.id).then(
function(a)
{
resolve();
}
);
});
}
我知道应该更改我的客户端以处理下载响应,但我不知道如何更改它。如何使下载过程开始?
任何帮助将不胜感激。