Created
August 19, 2015 10:48
-
-
Save deanhume/f9a338d12aeb983b15be to your computer and use it in GitHub Desktop.
A simple POST request using the fetch API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(url, { | |
method: 'POST', | |
headers: { | |
'auth': '1234' | |
}, | |
body: JSON.stringify({ | |
name: 'dean', | |
login: 'dean', | |
}) | |
}) | |
.then(function (data) { | |
console.log('Request success: ', data); | |
}) | |
.catch(function (error) { | |
console.log('Request failure: ', error); | |
}); |
Thank you!
please help me out
when i try to send this data i got the following error
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
this is my codes
You need to enable CORS on your server-side application. Please check it
@rakaar where can I find the CORS Documentation?
@AndreyPootMay
some useful links
- https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
- https://medium.com/@baphemot/understanding-cors-18ad6b478e2b#:~:text=Cross%2DOrigin%20Resource%20Sharing%20(CORS)&text=CORS%20is%20a%20mechanism%20which,.com%20calls%20api.com)
many frameworks like flask, node js have middleware packages which can be used directly
Thank You great and simple explanation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!!