您好,登錄后才能下訂單哦!
1.通過a標簽的方式來下載
<a href='' target='_blank'></a>
2.通過提交form表單的方式
var $form = $('<form action="'+url+'" method="post" target="rfFrame"></form>'); angular.forEach(d,function(v,k){ v = JSON.stringify(v); var $input = $('<input type="hidden" name="'+k+'"/>'); $input.attr('value',v); $form.append($input); }); $element.append($form); $form.submit(); $form.remove();
3.通過http的請求拿到文件流的方式
$http({ url : $scope.url, method : 'post', data : $scope.form.formdata, responseType : 'arraybuffer', }).then(function(d){ var data = d.data; var blob = new Blob([data], {type: "text/plain"}); //var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});//xlsx //var blob = new Blob([data], {type: "application/vnd.ms-excel"});//xls var downloadTitle = ''; if(d.headers('content-disposition').indexOf('filename') != -1){ downloadTitle = d.headers('content-disposition').split(';')[1].split('=')[1]; downloadTitle = decodeURI(downloadTitle); } if(typeof window.navigator.msSaveBlob !== 'undefined'){ window.navigator.msSaveBlob(blob, downloadTitle); }else{ var objectUrl = URL.createObjectURL(blob); var aForExcel = $("<a download='"+downloadTitle+"'><span class='forExcel'></span></a>").attr("href",objectUrl); $("body").append(aForExcel); $(".forExcel").click(); aForExcel.remove(); } });
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。