我使用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);
});
答案 0 :(得分: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)
答案 1 :(得分:0)
我遇到了同样的错误:
无法在“ XMLHttpRequest”上设置“ responseType”属性: 对于来自的同步请求,无法更改响应类型 文件。错误。
从我所做的少量研究来看,如果页面上的JS资产之一正在发出同步请求,这似乎会发生。有时,页面上包含的跟踪库正在进行同步调用,并弄乱了有角度的HTTP请求。我仍然没有找到解决方法:-)