Last active
April 7, 2017 02:50
-
-
Save watanabeyu/48ad3b215556cac6d2b7a75b5becf173 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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) | |
}) |
This file contains hidden or 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", { | |
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