Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载ajax返回的文件_Ajax_File_Yii - Fatal编程技术网

下载ajax返回的文件

下载ajax返回的文件,ajax,file,yii,Ajax,File,Yii,我在gridView中显示文件名。我使用了一个链接作为文件名。当用户单击文件名时,应下载文件。为此,我在javascript中使用ajax向控制器发送参数。 在我的控制器操作中,我使用代码 readfile( Yii::getPathOfAlias('webroot.order files').DIRECTORY_SEPARATOR.$order->user_id.DIRECTORY_SEPARATOR.$_GET['id'].DIRECTORY_SEPARATOR.$_GET['file

我在gridView中显示文件名。我使用了一个链接作为文件名。当用户单击文件名时,应下载文件。为此,我在javascript中使用ajax向控制器发送参数。
在我的控制器操作中,我使用代码

readfile( Yii::getPathOfAlias('webroot.order files').DIRECTORY_SEPARATOR.$order->user_id.DIRECTORY_SEPARATOR.$_GET['id'].DIRECTORY_SEPARATOR.$_GET['file']);
    Yii::app()->end();
但是结果作为字符串返回作为响应

有没有办法从返回的字符串下载文件?我知道不能从字符串下载文件,我只是想用ajax下载文件。

window.location=url\u to\u controller?不是ajax,但更简单。是的,它更简单,但它重定向页面,意味着完整的往返,这是我不想要的。实际上,我允许用户从gridView下载许多文件,以便用户可以多次单击同一页面。如果将http头设置为强制下载,则不会重定向页面