1

here is my code

products.service:

updateCategorie(ucategorie: Icategorie) {
const endpoint = this.url + 'api/Category/Edit';

const headers = new Headers();
headers.append('Authorization', 'Bearer ' + localStorage.getItem('access_token'));
const options = new RequestOptions({
  headers: headers
});

console.log('access_toke: ', localStorage.getItem('access_token'));

return this.http.put(endpoint, ucategorie, options)
.pipe(map((res) => {
  return res.json();
})).toPromise();

all the fields are not null and the access token is being sent product.component.ts:

updateCategorie() {
this.spinner.show();
console.log('catudata: ', this.categorieudata.value);
this.authent.updateCategorie(this.categorieudata.value).then((res) => {
  if (res) {
    this.spinner.hide();
    if (confirm(this.categorieudata.value.Category_name + 'have been updated')) {
      this.ngOnInit();
    }
  }
}, (err) => {
  this.spinner.hide();
  if (confirm('An error occured please try again')) {
    this.ngOnInit();
    console.log('###error: ', err);
  }
});
}

but i'm getting these error:

Access to XMLHttpRequest at 'http://api-accountingsystem.azurewebsites.net/api/Category/Edit' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

and i used the same method on another request it worked can anyone give me a hand please

mruanova
  • 6,351
  • 6
  • 37
  • 55
daniel
  • 75
  • 10
  • Possible duplicate of [Why does my JavaScript get a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error when Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-get-a-no-access-control-allow-origin-header-is-present) – p.s.w.g Feb 20 '19 at 23:35
  • Did u put Access-Control-Allow-Origin in your header response from API? – Mohit Saxena Feb 21 '19 at 06:31
  • actually my error was that i was sending an extra field without paying attention instead of affecting category_id i was adding categorie_id in my form Group – daniel Feb 21 '19 at 20:20

1 Answers1

0

my error was not in any of those functions i was sending an extra field in my FormGroup after i rechecked the fields is realized it

daniel
  • 75
  • 10