[英]Angular2 async/promises in shared-service JSON error at position 0
I'm getting an error Unexpected token < in JSON at position 0
in my shared-service to call an API. 我在共享服务
Unexpected token < in JSON at position 0
收到错误的Unexpected token < in JSON at position 0
以调用API。 I think its because of async request as sometimes the data is available and sometimes this error shows. 我认为这是由于异步请求造成的,因为有时数据可用,有时还会显示此错误。
The error log is point to this request. 错误日志指向此请求。
public getStores(): void {
this.retrieveResults().subscribe((results) => {
this.storesChanged.next(results.Results)
});
}
public retrieveResults(): Observable<any> {
return this.http.get(__env.nodeRedApiUrl + __env.storeSummaryPath)
.map(res => res.json())
}
can someone point out why this error is actually showing? 有人可以指出为什么实际上显示此错误吗? I just thought i'd be async call.
我只是认为我会被异步调用。 Can someone direct me how to deal with async/promise in Angular2.
有人可以指导我如何处理Angular2中的异步/承诺。
This happens mostly when you return HTML
instead of json
as expected. 大多数情况是在您返回
HTML
而不是预期的json
时发生的。 So check backend to make sure json
is returned. 因此,请检查后端以确保
json
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.