fetch error No 'Access-Control-Allow-Origin' header is present on the requested resource

The problem is not in your JavaScript code, it is in the API, the server doesn't support cross origin request, if you are the owner of this API you have to add 'Access-Control-Allow-Origin' header to the response with the allowed origins (* to allow from any origin). in some cases jsonp request may work.

Note: this problem happen only when the request is generated from the browser


The issue can be fixed by using "no-cors" argument after the url

fetch(url, {mode: "no-cors"})