Skip to content

Instantly share code, notes, and snippets.

@watanabeyu
Last active April 7, 2017 02:50
Show Gist options
  • Save watanabeyu/48ad3b215556cac6d2b7a75b5becf173 to your computer and use it in GitHub Desktop.
Save watanabeyu/48ad3b215556cac6d2b7a75b5becf173 to your computer and use it in GitHub Desktop.
const formData = new FormData()
formData.append("hoge","hogehoge")
formData.append("foo","bar")
fetch("url", {
headers:{
'Accept': 'application/json, */*',
//'Content-type':'application/json'
},
method:"post",
body:formData
})
.then(response => {
return response.json().then(json => ({
status: response.status,
json }))
})
.then(({
status,
json
}) => {
if (callback) callback(status, json)
})
fetch("url", {
headers:{
'Accept': 'application/json, */*',
'Content-type':'application/json'
},
method:"post",
body:JSON.stringify({hoge:"hogehoge",foo:"bar"})
})
.then(response => {
return response.json().then(json => ({
status: response.status,
json }))
})
.then(({
status,
json
}) => {
if (callback) callback(status, json)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment