Thursday 15 July 2010

javascript - Download zip file and trigger "save file" dialog from angular method -



javascript - Download zip file and trigger "save file" dialog from angular method -

i have standard angular code, triggered when button clicked:

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

but php script returns zip archive , contents ends in javascript variable, data. modify behaviour zip archive offered browser store on local disk. how accomplish that, keeping angular button handler?

in angular controller, inject $window , utilize this:

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

on server, create sure zip file served appropriate http headers prompt file download (content-disposition, mime type, ...).

javascript angularjs

No comments:

Post a Comment