I’m unable to use fetch API

Asked

Viewed 47 times

0

I’m unable to use fetch API

I don’t know what’s wrong with my code.

fetch('http://localhost:5000')
    .then(res => res.json)
    .then(data => console.log(data))

In the http://localhost:5000 has that data:

[
    {"name": "gustavo"},
    {"name": "mariana"},
    {"name": "daniel"}
]

You’re making these mistakes:

Access to fetch at 'http://localhost:5000/' from origin 'null' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves
your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Failed to load resource: net::ERR_FAILED

Uncaught (in promise) TypeError: Failed to fetch
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.