Categories
JavaScript Answers

How to make fetch API work with CORS after OPTIONS response with JavaScript?

Spread the love

Sometimes, we want to make fetch API work with CORS after OPTIONS response with JavaScript.

In this article, we’ll look at how to make fetch API work with CORS after OPTIONS response with JavaScript.

How to make fetch API work with CORS after OPTIONS response with JavaScript?

To make fetch API work with CORS after OPTIONS response with JavaScript, we can just call fetch.

For instance, we write:

(async () => {
  const response = await fetch("https://jsonplaceholder.typicode.com/posts")
  const data = await response.json()
  console.log(data)
})()

We make a GET request with fetch.

Then we get the JSON response body with response.json.

Conclusion

To make fetch API work with CORS after OPTIONS response with JavaScript, we can just call fetch.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *