angular - 服务器上的 Angular 可观察问题
问题描述
我在 Angular 6 中创建了一个服务,该服务通过订阅在 ngOnInit 上运行良好,但是一旦我尝试通过函数/单击事件获得响应,我就会收到以下错误。
错误 DOMException:无法在“XMLHttpRequest”上设置“responseType”属性:无法更改从文档发出的同步请求的响应类型。
我怀疑我在做一些愚蠢的事情 - 数据在 fetch 中返回正常。然后调用所以我排除了服务器配置,到目前为止仍在通过 Angular 理论工作,所以在这里发布以防万一它对某人来说是显而易见的更多经验。
localhost 它工作正常,但是当我将代码构建/移动到服务器时,出现错误 - 有什么想法吗?
亲切的问候雷切尔
服务
export class GetVehicleResultsService {
url = 'SOME_URL';
constructor(private http: HttpClient) {}
getVehicles() {
return this
.http
.get<Vehicle>(`${this.url}`, {
responseType: 'json',
params: {
keyword: '*'
}
});
}
}
零件
ngOnInit() {
this
.getVehicleResultsService
.getVehicles()
.subscribe(
vehicles => {
this.vehicles = vehicles.response.docs;
this.facets = vehicles.facet_counts.vcj_facet_fields;
});
}
// this call works and consoles the data
test() {
fetch('SOME_URL')
.then(response => response.json())
.then(json => console.log(json));
}
// this doesn't work
test() {
this
.getVehicleResultsService
.getVehicles()
.subscribe(
vehicles => {
this.vehicles = vehicles.response.docs;
this.facets = vehicles.facet_counts.vcj_facet_fields;
});
}
解决方案
推荐阅读
- html - Emscripten - 如何将我的makefile与emcc一起使用而不是gcc?
- inno-setup - 用单独页面上的单选按钮替换 Inno Setup 安装类型组合框(类似安装 Shield)
- python - 用户标准和“make_scorer”
- twitter - 从视频推文中获取视频观看次数
- jquery - tooltip.js popper.js 使用示例
- sql-server - 调试参数
- wcf - 在 Docker 容器中运行 WCF 主机(控制台应用程序)
- java - 如何在 Android P 上使用 apache http
- perl - '->to()' 可以在 Mojolicious::Lite 中使用吗?
- php - Apache/PHP/Win 内存问题,两种不同的系统+代码。同样的问题