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) },
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With