简体   繁体   English

在返回响应之前未执行回显

[英]Echo not being executed before return response

I have a really simple question.我有一个非常简单的问题。 I have this Controller in my Laravel application, that returns a zip file download, depending on what the user selected.我的 Laravel 应用程序中有这个控制器,它返回一个 zip 文件下载,具体取决于用户选择的内容。 So far so good.到目前为止,一切都很好。 I also have this echo just before the return:在返回之前我也有这个回声:

echo "<script> alert('test') </script>";

return response()->download(public_path($fileName));

My question is: the "echo" is not being executed, but if i remove the return, it is executed.. isn't the "echo" supposed to execute before the return ?我的问题是:“回声”没有被执行,但是如果我删除返回,它会被执行..“回声”不是应该在返回之前执行吗? Why is it not being executed?为什么它没有被执行?

download() forces browser to well... download given file, so there is no place to display echo text. download()强制浏览器很好地...下载给定的文件,因此没有地方显示回显文本。 You can use for example redirect to download page to firstly display alert box.您可以使用例如重定向到下载页面来首先显示警报框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM