当我尝试使用 laravel ajax 中的下载按钮下载文件时,它无法正常工作,并且我无法下载文件。
下面是我的代码:
<button type="button" request_id="'.$data->id.'" class="btn btn-success download_request_btn" > Download </button>';
控制器:
public function downloadReport(Request $request)
{
$request_id = $request->request_id;
$downloadReport = Upload::where('id', $request_id)->first();
$upload_report = $downloadReport->upload_report;
$headers = array(
'Content-Type: application/pdf',
'Content-Type: application/docx',
);
$url= url('storage/documents/request/'. $upload_report);
return response()->download($url);
}
阿贾克斯:
$(document).on('click', '.download_request_btn', function(){
var request_id = $(this).attr('request_id');
console.log(request_id);
var formData = new FormData();
formData.append('request_id',request_id);
jQuery.ajax({
type: "post",
url: site_url+"/DownloadAjax",
data: formData,
contentType:false,
processData:false,
success: function (res) {
}
});
});
呼唤远方
MM们
翻翻过去那场雪
相关分类