订阅httpClient get方法会导致XMLHttpRequest错误

问题描述 投票:1回答:1

我用angular 5(最新版本)设置了一个新的应用程序,我遇到了以下错误:

Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be changed for synchronous requests made from a document.

如果需要我可以提供代码但是错误已经发生了:

this.http.get('https://google.com').subscribe(data => {
  console.log(data);
});
angular angular-httpclient
1个回答
0
投票

用它来获取一个Observable of string

const options: { responseType: 'text'};
this.httpClient.get(url, options)

你必须为json指定类型

const options: { responseType: 'text' as 'json'};
this.httpClient.get(url, options)
© www.soinside.com 2019 - 2024. All rights reserved.