Skip to content

Instantly share code, notes, and snippets.

@p410n3
Created May 23, 2018 20:55
Show Gist options
  • Save p410n3/a8f7d320641df69aed2225c1ecf08a9f to your computer and use it in GitHub Desktop.
Save p410n3/a8f7d320641df69aed2225c1ecf08a9f to your computer and use it in GitHub Desktop.
Fetch API so I dont ferget it again
var requestBody =
'1=' + stuff1 + '&' +
'2=' + stuff2 + '&' +
'3=' + stuff3;
fetch('https://some-api.tld', {
method: 'post',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: requestBody
})
.then((res) => {
return res.text();
})
.then((data) => {
if (data.includes('error')) {
alert('shit');
} else {
alert(data);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment