Created
May 23, 2018 20:55
-
-
Save p410n3/a8f7d320641df69aed2225c1ecf08a9f to your computer and use it in GitHub Desktop.
Fetch API so I dont ferget it again
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
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