Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created August 19, 2015 10:48
Show Gist options
  • Save deanhume/f9a338d12aeb983b15be to your computer and use it in GitHub Desktop.
Save deanhume/f9a338d12aeb983b15be to your computer and use it in GitHub Desktop.
A simple POST request using the fetch API
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);
});
@JaeHyeonKim19
Copy link

thx!!:)

@IAmLeSpy
Copy link

no problem

@LiveBacteria
Copy link

Thanks!!

@encore-by-dev
Copy link

Thank you!

@almdhhish
Copy link

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

<script type="text/javascript"> const data = { username: 'username', password: 'password' }; fetch('https://verification.nhif.or.tz/nhifservice/token', { method: 'POST', // or 'PUT' headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); }); </script>

@rakaar
Copy link

rakaar commented Aug 6, 2020

@almdhhish

You need to enable CORS on your server-side application. Please check it

@AndreyPootMay
Copy link

@rakaar where can I find the CORS Documentation?

@rakaar
Copy link

rakaar commented Aug 11, 2020

@rpralica
Copy link

Thank You great and simple explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment