因此,我编写了一个函数从C#控制器中提取数据。它被拉到一个FormData对象中,然后转换成一个数组,这个数组应该被分解成逗号分隔的值。
然而,当我下载csv时,这就是我得到的(截图):
http://postimg.org/image/wex20t1h3/
这是我的Angularjs控制器代码:
angular.module("umbraco")
.controller("ExportAllController", function ($scope, $http) {
$scope.filedownload = {};
$scope.exportAll = function () {
var downloadUrl = " /umbraco/backoffice/api/ExportDictionaryAll/ExportAll";
var fd = new FormData();
fd.append('file', $scope.filedownload);
$http.get(downloadUrl, fd)
.success(function (fd) {
// ok
$scope.fd = fd.split(',');
console.log($scope.fd);
alasql('SELECT * INTO CSV("AllDictionaryItems.csv" ) FROM ?', [$scope.fd]);
})
.error(function () {
// handle upload error
alert("Download Unsuccessful!");
});
};
});发布于 2016-04-25 09:00:01
angular.module("umbraco")
.controller("ExportAllController", function ($scope, $http) {
$scope.filedownload = {};
$scope.exportAll = function () {
var downloadUrl = " /umbraco/backoffice/api/ExportDictionaryAll/ExportAll";
var fd = new FormData();
fd.append('file', $scope.filedownload);
window.open(downloadUrl, "_blank");
$http.get(downloadUrl, fd)
.success(function (fd) {
// ok
alert("Download Successful!");
})
.error(function () {
// handle upload error
alert("Download Unsuccessful!");
});
};
$scope.greetings = [{
name: "Export All Dictionary Items to CSV",
def: "Click the button below to export a CSV file with all current dictionary items."
}]
});我错过了一个window.open(downloadUrl, "_blank");
https://stackoverflow.com/questions/36790200
复制相似问题