我正在使用 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()
时,总是返回以下错误:
JSONP injected script did not invoke callback.
并且响应
始终为空。我是否遗漏了某个步骤?
最佳答案
您没有在请求中提供回调。在下面的示例中,提供回调的查询参数是 c (它实际上取决于服务)。您始终需要为此类参数提供 JSONP_CALLBACK 值。
const url = 'http://exampleurl:6000/GetSomeData(inputParams=@test1)?callback=JSONP_CALLBACK&@test1= {hasData=true}';
关于javascript - Angular 8 jsonp 回调未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58564366/