Below is the code snippet:
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 fields have values 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);
}
});
}
However, encountering the following 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.
I have successfully used the same method for another request. Could someone kindly assist me with this issue?