I'm trying to get the data from an api and use d3.js to plot the graph. But I'm unable to get the data due to 401 Authorization error. How to pass the token value to the d3 method ?
service.ts
//This service is what i used to get data . I need to use this for plotting the graph also.
rec_source(){
var headers = new HttpHeaders().set('Authorization', 'Token ' + localStorage.getItem('usertoken'));
headers.append('Accept', 'application/json');
var options = {
headers: headers
};
return this.httpClient.get('api/recruit/fetch_recruitment_details',options)
}
component.ts
//what is the changes I have to make here?
d3.json('api/recruit/fetch_recruitment_details/')
.then(function(data){
data.forEach(function(d){
console.log(d);
})
})
// error
//header error
尝试:您应在集合授权中使用Bearer而不是Token,例如:
var headers = new HttpHeaders().set('Authorization', 'Bearer ' + localStorage.getItem('usertoken'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.