问题
So I have written a function to pull data from a C# controller. It is pulled through into a FormData object and then converted into an array, the array is supposed to be broken down into comma separated values.
however when I download the csv this is what I get (screenshot):
http://postimg.org/image/wex20t1h3/
Here is my Angularjs controller code:
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!");
});
};
});
回答1:
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."
}]
});
I was missing a window.open(downloadUrl, "_blank");
来源:https://stackoverflow.com/questions/36790200/alasql-csv-pulling-through-functions