angular - Angular 6 - 错误:JSONP 注入脚本未调用回调
问题描述
对于 jsonp 请求,我收到此错误:
Error: JSONP injected script did not invoke callback.
不知道如何使用回调。
getSellers(): Observable<Seller[]> {
return this.http.jsonp<Seller[]>(this.apiRoot + '/sellers', 'callback')
.pipe(
tap(_ => console.log('fetched sellers')),
catchError(this.handleError('getSellers', []))
);
}
错误:
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "JSONP Error", url: "http://localhost:4300/api/sellers?__ng_jsonp__.__req$%7Bthis.times%7D.finished=ng_jsonp_callback_0", ok: false, …}
error: Error: JSONP injected script did not invoke callback. at HTMLScriptElement.onLoad (http://localhost:4200/vendor.js:7224:32) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2743:31) at Object.onInvokeTask (http://localhost:4200/vendor.js:36916:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2742:36) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2510:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:2818:34) at invokeTask (http://localhost:4200/polyfills.js:3862:14) at HTMLScriptElement.globalZoneAwareCallback (http://localhost:4200/polyfills.js:3888:17)
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
message: "Http failure response for http://localhost:4300/api/sellers?__ng_jsonp__.__req$%7Bthis.times%7D.finished=ng_jsonp_callback_0: 0 JSONP Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "JSONP Error"
url: "http://localhost:4300/api/sellers?__ng_jsonp__.__req$%7Bthis.times%7D.finished=ng_jsonp_callback_0"
解决方案
尝试这个
getSellers(): Observable<Seller[]> {
return this.http.get(this.apiRoot + '/sellers')
.pipe(
tap(_ => console.log('fetched sellers')),
catchError(this.handleError('getSellers', []))
);
}
推荐阅读
- python - 为什么对 dict2 内的嵌套 dict 的更改会影响 dict1?
- linkedin - 公司页面 API 上的 Linkedin 共享根本不起作用。
- ios - 拖动时 UIScrollView 键盘关闭不会在 iOS 11 上使用自定义 inputView 键盘在 UIView 上调用 resignFirstResponder
- jquery - 将属性 headerClass 添加到 display:column
- firebase - 我可以将 UTM 参数传递给 Firebase Analytics 用户维度吗?
- spring-boot - 用新的替换旧的 Spring Boot Jar
- c# - 如何阻止 NCalc 写入控制台?
- c# - 如何计算多维数组c#(Unity)上的特定值
- android - 为什么不在 android mapsforge 地图中显示任何标记?
- css - 不同计算机上的不同滚动条类型