我正在通过我的服务进行保存,并且保存得很好:
this.generalService.saveAllGameData(this.gameData).subscribe(
data => {
console.log(data);
this.deleteUnrequiredFilesOnSave();
this.notifyService.changeNotify("Saved!");
this.router.navigate(["/rooms"]);
},
error => {
},
() => {
console.log("Posted!");
}
);
这是服务中的代码:
saveAllGameData(newData: any): Observable<any> {
const body = newData;
return this.http.post("" + this.apiDomain() + "/api/gameCentre", body)
}
但是数据回调中的所有内容都不会被调用。有什么想法吗?
甚至 console.log("Posted!");
也不起作用。
最佳答案
从评论来看,很可能由于请求中缺少正确的响应类型而没有触发回调。
尝试以下操作
saveAllGameData(newData: any): Observable<any> {
const body = newData;
return this.http.post(
"" + this.apiDomain() + "/api/gameCentre",
body,
{ responseType: 'text' }
);
}
默认的responseType
是'json'
。
关于angular - 后回调没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66707164/