我想在我的视图上显示下载链接按钮(如果我的ajax成功) follwings是我的下载代码,用于发送ajax响应和显示视图
<div class="blog-moder-button">
<a href="public_path('files').'/'.$request->file_name" class="button-md dark-button downlds">
Download PDF
</a>
</div>
以下是我的控制器
public function
downloadform(Request $request) {
$validator = Validator::make($request->all(),[
'name' => 'required',
'email' => 'required|email',
'file_name' => 'required',
]
);
if ($validator->passes()) {
$msg= array();
// $msg['success'] = '<div class="alert alert-success"> Successfully Registered</div>';//it is working
$msg['success'] = '<div class="blog-moder-button"> <a href="public_path('files').'/'.$request->file_name" class="button-md dark-button downlds"> Download PDF</a></div>';//it is not working
}
return response()->json($msg);
}
答案 0 :(得分:1)
不要在控制器中渲染html,这是您视图的工作。
要触发文件下载响应,请使用以下命令:
https://myapp.example.com:9200