Angular 角度6错误:注入JSONP的脚本未调用回调

Angular 角度6错误:注入JSONP的脚本未调用回调,angular,angular6,jsonp,angular-httpclient,Angular,Angular6,Jsonp,Angular Httpclient,在Angular 6项目中工作并尝试访问公共API,因此我需要使用JSONP来绕过CORS。我的代码出现以下错误: “错误:注入JSONP的脚本未调用回调”。 我认为回调参数的名称有问题 我在这里和Github上花了大量时间研究类似的问题,最显著的是:并尝试用以下内容替换JSONP_回调: ng_jsonp{u_req${this.times}.finished __ng_jsonp__________要求6_完成 完全忽略回调参数 但我还没有找到成功 import { Injectable }

在Angular 6项目中工作并尝试访问公共API,因此我需要使用JSONP来绕过CORS。我的代码出现以下错误: “错误:注入JSONP的脚本未调用回调”。 我认为回调参数的名称有问题

我在这里和Github上花了大量时间研究类似的问题,最显著的是:并尝试用以下内容替换JSONP_回调:

ng_jsonp{u_req${this.times}.finished

__ng_jsonp__________要求6_完成

完全忽略回调参数

但我还没有找到成功

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from "rxjs/operators";

export class CoursesAPIService {

    constructor(private http: HttpClient) {}

    getData() {
        var url = 'http://web-app.usc.edu/web/soc/api/classes/?callback=JSONP_CALLBACK'
        console.log("calling: " + url)

        return this.http.jsonp(url, "callback")
           .pipe(map(data => {
               console.log("Inside map")

               console.log(data)
           })
        ).subscribe()
    }
}    

我有一个类似的问题,在使用HttpClient.jsonp()时,我发现不应该传递callback=jsonp\u callback参数和值

// try this instead
var url = 'http://web-app.usc.edu/web/soc/api/classes/?'
如果您检查了github中的源代码

在第1121 1461行(由于本节正在进行,所以只需搜索jsonp()函数即可),您会注意到他们将再次发送该参数。您当前的url变量将变成:

// this is what's probably giving you issues after the jsonp function's internal functions are processed 
'http://web-app.usc.edu/web/soc/api/classes/?callback=JSONP_CALLBACK&callback=JSONP_CALLBACK'