0

My component

 saveStudentDetails(values) {
  const studentData = {};

  studentData['s_pNumber'] =  values.s_pNumber;
  studentData['s_address'] =  values.s_address;
  studentData['s_pCode'] =  values.s_pCode;
  studentData['s_city'] =  values.s_city;
  studentData['s_state'] =  values.s_state;
  studentData['s_country'] =  values.s_country;

  this.crudService.createAddress(studentData).subscribe(result => {
    this.student = result;
    this.toastr.success('Your data has been inserted', 'Success !', { positionClass: 'toast-bottom-right' });
     this.router.navigate(['/finance']);
  },
    err => {
      console.log('status code ->' + err.status);
      this.toastr.error('Please try again', 'Error !', { positionClass: 'toast-bottom-right' });
});}

My Service

createAddress(data) {

const postHttpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
 };

postHttpOptions['observe'] = 'response';

return this.http.put(this.url + 'address/${id}', data, postHttpOptions)
.pipe(map(response => {
       return response;
  }));
}

Why does my service did not send any data to my back-end, when i press a button to update it does not show any error. I just return true and navigate to finance page instead of showing any error. But in my database, the data is not updated. But when i tested my back-end using postman, it is working. Does not have any error.

Dory
  • 95
  • 4
  • 19
  • 3
    Have you observed the network tab to see what request is being made? From a glance it looks like it should make *a* request - whether it's the correct request is a different story. Also the pipe to map response to response is superfluous – Michael Mar 16 '19 at 05:27
  • https://imgur.com/a/Cr7Bo9A the status code is 200 but i didn't really sure about the request URL, is it correct? or maybe must be something wrong with my service or component – Dory Mar 16 '19 at 06:50
  • maybe something with CORS (Postman don't care about it, browsers do), check this out https://stackoverflow.com/a/7069902/5031771 – Wilhelm Olejnik Mar 16 '19 at 13:08
  • yeah already did that, but still the same – Dory Mar 16 '19 at 14:08

0 Answers0