Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONP injected script did not invoke callback

Tags:

jsonp

angular

I'm trying to get data from a Rest Api:

I tried following:

var headers: Headers= new Headers({  'dataType': 'jsonp'});
    let options = new RequestOptions({ headers: headers });

    return this.http.get('http://aaaddds.de/redmine/issues.json?limit=1200&callback=JSONP_CALLBACK', options)
      .map(this.extractData);

it doesn't work because of:

 No 'Access-Control-Allow-Origin' header

So when I try JSONP

let params = new URLSearchParams();
params.set('callback', 'JSONP_CALLBACK');
params.set('project_id', '7');
params.set('key', '42d3db30ab061a9f630df1f476c4d127f98d5ad2');
params.set('limit', '1200');


return this.jsonp.get('http://aaaddds.de/redmine/issues.json', { search: params })
  .map(this.extractData);

it says :

Uncaught ReferenceError: __ng_jsonp____req0finished is not defined JSONP injected script did not invoke callback

When I do a Jquery ajax get it works:

   $.ajax({

      url: url,
      type: 'GET',
      dataType: 'jsonp',
      success: function (datsa: any) {
        console.log(datsa);
      },
      error: function (e : any) { alert(e.toString) },
    });
like image 533
user3369579 Avatar asked Oct 18 '22 06:10

user3369579


1 Answers

I think that the parameter you provided for your callback isn't callback. In fact, this name depends on the target service and can be callback, c or something else...

To diagnose your problem, you should have a look at the Network tab of devtools in your browser to see the content of the response. It should be something like that:

__ng_jsonp__.__req0.finished({ ... })

__ng_jsonp__.__req0 is the name of the callback internally handled by Angular2.

like image 78
Thierry Templier Avatar answered Nov 15 '22 06:11

Thierry Templier