是的。我知道这个主题似乎是重复的,但是我使用了stackoverflow中的几种替代方法,但是实际上所有尝试都失败了。
场景
要求
路由器
Route::get('/download/{id?}', 'Mensagem\DocumentoController@download')->name('Documento.download');
控制器
public function download()
{
return response()->download(storage_path('app/' . 'storage_app_file.pdf'));
}
jQuery / Ajax
/* DOUBLE CLICK ROW */
$datatable.find("tbody").on("dblclick", "tr", function() {
let data = table.row(this).data();
$.ajax({
url: '{{route("Documento.download")}}',
type: "get",
contentType: false,
processData: false,
cache: false,
beforeSend: function() {
console.log("double click beforeSend...");
},
success: function() {
console.log("DOUBLE CLICK ROW: success...");
}
});
});
出于某种原因,只需使用...
{{--window.open = '{{route("Documento.download")}}';--}}
...甚至在控制器中更改文件名,总是在...之前下载相同文件。
我决定制作一个Response宏:
\Response::macro('attachment', function ($content) {
$rand = mt_rand(11111, 99999);
$filename = 'download-' . "{$rand}" . '.pdf';
$headers = [
'Content-type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $filename .
'"',
'Content-Transfer-Encoding' => 'Binary"',
];
return \Response::make($content, 200, $headers);
});
...并在控制器中:
$file = \Storage::disk('local')->get( $name );
return response()->attachment( $file );
...在“双击”中...
let myWindow = window.open('{{route("Documento.download")}}', '_blank', 'location=yes,height=400,width=300,scrollbars=yes,status=yes');
setTimeout(() => myWindow.close(), 3000);
答案 0 :(得分:1)
为什么要使用ajax?我认为最简单的方法是:
t1.STATION LIKE '*' & t2.STATION & '*'