JavaScript 有关文件上传的总结

1.文件上传时的处理

$scope.submit = function(){
    var url = $scope._datalistmodel.impexp.imp;
    var t_file = new FormData(document.getElementById('upload_file'));//id是form表单的id
    $http({
        headers : {
            'content-type':undefined        },
        url : url,
        data : t_file,
        method : 'post',
        transformRequest:angular.identity    }).then(function(d){
    });};

2.文件下载

根据链接下载文件时,http请求不能打开下载窗口,用a标签

<a href='{{file.$href("_download")}}'>
    <i class='glyphicon glyphicon-save attach-operate'></i>
</a>


猜你喜欢

转载自blog.51cto.com/dd118/2167620