我将文件加载到服务器时遇到问题。我遵循演示中提供的结构:
file.upload = this.Upload.upload({
url: "/api/license/upload",
method: "POST",
data: {
name:file.name
},
file: file
}).then(function (resp:any) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp:any) {
console.log('Error status: ' + resp.status);
}, function (evt:any) {
var progressPercentage = parseInt(evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
}
但是,当我尝试上传文件时,在服务器的响应中我得到200(这没关系),但随后应用程序崩溃了以下内容:
SyntaxError: Unexpected token Y
at Object.parse (native)
at vc (http://localhost:4000/dist/vendor.min.js:20:480)
at Zb (http://localhost:4000/dist/vendor.min.js:87:229)
at http://localhost:4000/dist/vendor.min.js:88:143
at m (http://localhost:4000/dist/vendor.min.js:12:322)
at dd (http://localhost:4000/dist/vendor.min.js:88:125)
at d (http://localhost:4000/dist/vendor.min.js:89:380)
at http://localhost:4000/dist/vendor.min.js:124:113
at n.$eval (http://localhost:4000/dist/vendor.min.js:138:221)
at n.$digest (http://localhost:4000/dist/vendor.min.js:135:233)
关于可能出现什么问题的任何想法?
答案 0 :(得分:0)
好吧,我发现问题是什么:来自服务器的响应是字符串形式,而不是JSON。