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
.