【发布时间】:2019-08-26 07:35:27
【问题描述】:
我试图从服务器下载 .xls 文件,但它抛出如下错误:->
错误是:
SyntaxError: Unexpected token � in JSON at JSON.parse 的位置 0 () 在 XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:31219:51) 在 ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2761:31) 在 Object.onInvokeTask (http://localhost:4200/vendor.js:72221:33) 在 ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2760:36) 在 Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2528:47) 在 ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [作为调用] (http://localhost:4200/polyfills.js:2836:34) 在调用任务 (http://localhost:4200/polyfills.js:3880:14) 在 XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.js:3906:17) 文字:“��ࡱ�;��”
在我的组件中,我实现了调用服务的函数,并且我正在使用文件保护程序来保存文件,但是它抛出错误。
download.component.ts:->
import * as FileSaver from 'file-saver';
export_licence(){
this.service.export_licence().subscribe((file: Blob) => {
FileSaver.saveAs(file,'degreeCertificate.xls');
}, (err) => {
console.log("Download Error:", err);
});
}
download.service.ts :->
export_licence() {
return this.http.post(this.export_licence_url,{responseType: "blob"});
}
我应该能够从服务器下载 .xls 文件,任何帮助将不胜感激。
【问题讨论】:
标签: javascript angular6