您好,登錄后才能下訂單哦!
1.通過a標(biāo)簽的方式來下載
<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(); } });
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。