Javascript 角形罐';无法获取响应状态文本

Javascript 角形罐';无法获取响应状态文本,javascript,ajax,angular,httpclient,Javascript,Ajax,Angular,Httpclient,因此,这个ajax被发送到我的spring服务器,服务器将数据正确地保存在数据库中,它基本上运行良好 但我无法获取响应状态,我的意思是如何获取服务器返回的200响应状态编号或文本?,试试这个,你可以通过观察键传入一个对象来获得完整的响应 export class GitComponent implements OnInit { http: HttpClient; headerForAjax: HttpHeaders; constructor(http: HttpClient) {

因此,这个ajax被发送到我的spring服务器,服务器将数据正确地保存在数据库中,它基本上运行良好


但我无法获取响应状态,我的意思是如何获取服务器返回的
200
响应状态编号或文本?

试试这个,你可以通过观察键传入一个对象来获得完整的响应

export class GitComponent implements OnInit {
  http: HttpClient;
  headerForAjax: HttpHeaders;

  constructor(http: HttpClient) {
    this.http = http;
  }

  ngOnInit(): void {
    const headers = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzYXNobyIsImF1dGgiOiJST0xFX1VTRVIiLCJleHAiOjE1MjQwODcyMzJ9.MUv5RgI9LxQyrrCfjfX8HR2-XiQmz4vjLqH7V_0Du7VFLC0WrK_y3FfeNoT2Nj_uguIK2ss7jv-LNiHuCGtz4A';
    this.headerForAjax = new HttpHeaders().set('Authorization', headers);
    const linkBindingModel = {
      title: 'angular2',
      linkUrl: 'angularUr2l',
      imageUrl: 'imageUrl22'
    };
    this.http.post('http://localhost:8080/links/add', linkBindingModel, {headers: this.headerForAjax}).subscribe((e) => {
      console.log(e);
    });
  }
}
this.http.post('http://localhost:8080/links/add', linkBindingModel, {headers: 
  this.headerForAjax, observe: 'response'}).subscribe((response) => {
  console.log(response.status); // response status 
  console.log(response.body); // response body (returned response)
});