Angular 8 jsonp 回调未调用
Angular 8 jsonp Callback not invoked
我正在使用 Angular 8 和 HttpClientJsonpModule。这是我的自定义获取函数:
public fetch(): Observable<any> {
// This url has been obfuscated but you get the gist. This is the expected format so I can't alter the string
const url = 'http://exampleurl:6000/GetSomeData(inputParams=@test1)?@test1={hasData=true}';
return this.http.jsonp(url, 'callback')
.pipe(
map(response => {
// always returns null
console.log(response);
})
);
}
当我调用 this.fetch()
时总是出现以下错误 returns:
JSONP injected script did not invoke callback.
并且 response
始终为空。我错过了什么地方吗?
您没有在请求中提供回调。在下面的示例中,提供回调的查询参数是 c (它实际上取决于服务)。您始终需要为此类参数提供 JSONP_CALLBACK 值。
const url = 'http://exampleurl:6000/GetSomeData(inputParams=@test1)?callback=JSONP_CALLBACK&@test1={hasData=true}';
我正在使用 Angular 8 和 HttpClientJsonpModule。这是我的自定义获取函数:
public fetch(): Observable<any> {
// This url has been obfuscated but you get the gist. This is the expected format so I can't alter the string
const url = 'http://exampleurl:6000/GetSomeData(inputParams=@test1)?@test1={hasData=true}';
return this.http.jsonp(url, 'callback')
.pipe(
map(response => {
// always returns null
console.log(response);
})
);
}
当我调用 this.fetch()
时总是出现以下错误 returns:
JSONP injected script did not invoke callback.
并且 response
始终为空。我错过了什么地方吗?
您没有在请求中提供回调。在下面的示例中,提供回调的查询参数是 c (它实际上取决于服务)。您始终需要为此类参数提供 JSONP_CALLBACK 值。
const url = 'http://exampleurl:6000/GetSomeData(inputParams=@test1)?callback=JSONP_CALLBACK&@test1={hasData=true}';