【发布时间】:2011-06-16 03:35:47
【问题描述】:
在我的 HTML 页面上,我向一个应该强制下载的 php 脚本发出了 JQuery ajax 请求,但什么也没发生?
在我的 html 页面上(在链接的单击事件处理程序中)...
var file = "uploads/test.css";
$.ajax(
{
type : "POST",
url : "utils/Download_File.php",
data : {"file":file}
})
Download_File.php 脚本看起来像这样
<?php
Download_File::download();
class Download_File
{
public static function download()
{
$file = $_POST['file'];
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment');
readfile('http://localhost/myapp/' . $file);
exit;
}
}
?>
但是由于某种原因什么都没有发生?我查看了萤火虫中的响应标头,看不到任何问题。我正在使用 Xampp。非常感谢任何帮助。
谢谢!
【问题讨论】:
-
这不是它的做法。您需要将
location.href设置为您要下载的文件,或者使用iframe。看看这个问题: