繁体   English   中英

Subscribe()方法在Microsoft Edge中不起作用

[英]Subscribe() method not works in Microsoft Edge

我正在使用subscribe()获取json格式的值。 此值显示在屏幕中。

问题是在Microsoft Edge中此方法无效。 它返回了HttpResponse 0的错误。但是,在Chrome和Firefox中可以正常工作。

这是我的代码:

if (this.machine.length === 0) {
  this.simulatorService.getAks(this.codIm, this.codCS)
    .subscribe(
      data => {
        console.log('works!');
        this.machine= data;
      },
      error => {
        console.log(error);
        this.machine= [];
      }
    );
}

因此,我需要使用除.subscribe()之外的其他方法? 什么?

那么,使代码在Microsoft Edge上运行的最佳方法是什么?

---------- 更新1 -----------

这段代码是我的getAsks 这是一条返回带有一些数据的json文件的路由。

  getAsks(codIm: codIm, codCS: codCS): Observable<Array<Equip>> {

    return this.http.get<Array<Equip>>(
      `${this.urlBase}v1/simulator/machine/${codIm}/${codCS}`,
      {
        headers: new HttpHeaders({
          'Content-Type': 'application/json'
        })
      });
  }

错误无效的HttpResponse可能是因为您的api未返回正确的标头。 因此,我建议您检查${this.urlBase}v1/simulator/machine/${codIm}/${codCS}以及您的api是否正确处理了此链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM