Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/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
Javascript 从angular方法下载zip文件并触发“保存文件”对话框_Javascript_Angularjs - Fatal编程技术网

Javascript 从angular方法下载zip文件并触发“保存文件”对话框

Javascript 从angular方法下载zip文件并触发“保存文件”对话框,javascript,angularjs,Javascript,Angularjs,我有一个标准的角度代码,点击按钮时会触发: $scope.downloadAll = function () { $http.get("download.php?id=" + $scope.id).success(function (data) { }).error(function () { $scope.status = "Error: can not download table data from server."; }); } 但是我的p

我有一个标准的角度代码,点击按钮时会触发:

$scope.downloadAll = function () {   
  $http.get("download.php?id=" + $scope.id).success(function (data) {
    }).error(function () {
        $scope.status = "Error: can not download table data from server.";
    }); 
 }

但是我的php脚本返回一个zip归档文件,其内容因此以javascript变量data结尾。我想修改行为,以便浏览器提供zip存档以存储在本地磁盘上。如何实现这一点,保持angular按钮处理程序?

在angular controller中,注入$window并按如下方式使用它:

$scope.downloadAll = function () {
  $window.location.href = "/download.php?id=" + $scope.id;
}

在服务器上,确保为zip文件提供了适当的http头,以提示文件下载内容配置、mime类型等。

window.location=download.php?id=+$scope.id;有没有办法指定下载文件名?与使用相同的方式,但没有锚定标记?这就是内容处置的服务器头