alasql CSV pulling through functions

人走茶凉 提交于 2020-01-06 14:45:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!