I am doing a fetch to an API, a super simple method, I only have to print the json that the api brings in a console.log, but for some reason CORS blocks me, I have not been able to solve it, I attach the FETCH code and the error code , Cheers.
function getDepartments() {
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("http://helpdeskwebservices.tk/api/Departamentos", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
getDepartments();
Thank you very much.
That happens because you don't have CORS configured within your API.
I show you this way since currently with this account I cannot comment.
If you are working as in this video: Configuracion cors the following will help you.
CORS# Configuration