通过ajax请求下载php文件

时间:2010-10-29 14:07:53

标签: php ajax

我正在尝试通过ajax请求下载文件。 我的php文件中的代码低于下载

$filedata="File data here"
header("Content-type: application/octet-stream");
header("Content-Disposition:attachment; filename=report.txt");
header('Content-Transfer-Encoding: binary');
header("Pragma: public");
header("Expires: 0");
echo $filedata;

它给了我ajax响应但没有提供文件下载对话框。有什么办法吗? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

我认为ajax阻止了请求。

由于它从服务器读取的ajax可能不会触发文件保存对话框。