deliveryCode传的你要下载的code
mimeograph:function(deliveryCode,that){ //原生ajax var xhr = new XMLHttpRequest(); //post方式请求后台的路径 // xhr.open('get', window.BAOSIGHT.API.DELIVERY.PRINT_INFO+'?deliveryCode='+deliveryCode,true); xhr.open('post',window.BAOSIGHT.API.DELIVERY.PRINT_OUTSIDE_THE_PACKAGE,true); //导出的Pdf是二进制数据类型,所以设置为arraybuffer xhr.responseType = 'arraybuffer'; //请求头(key,value),请求头可以设置多个key-value对 xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8'); xhr.setRequestHeader('Authorization', that.global.getLocalStorage("Authorization") ); // var formData = new FormData(); // formData.append('deliveryCode',that.defaults.deliveryCode); // console.log(formData) //返回成功,导出的Pdf文件 xhr.onload = function () { if (this.status == 200) { // new Blob 默认转换 blod,转arraybuffer需要增加 type var blob = new Blob([this.response],{type: "arraybuffer"}); // var fileName = 'lichun.pdf' if (window.navigator && window.navigator.msSaveBlob) { //兼容ie 下载 msSaveBlob 仅支持保存 msSaveOrOpenBlob 支持保存or代开 window.navigator.msSaveBlob(blob, fileName); }else{ var a = document.createElement('a'); var url = window.URL.createObjectURL(blob); a.href = url; //设置文件名称 a.download = '包装信息外.pdf'; a.click(); } } }; //请求的参数,json格式,后台要用json格式接收 xhr.send(JSON.stringify(deliveryCode)); },