Skip to content

Instantly share code, notes, and snippets.

@horitaku1124
Created December 6, 2021 05:59
Show Gist options
  • Save horitaku1124/bc8dce6f32d0e0e67fd7038ef2e1548e to your computer and use it in GitHub Desktop.
Save horitaku1124/bc8dce6f32d0e0e67fd7038ef2e1548e to your computer and use it in GitHub Desktop.
async function postFormData(url = '', data = "") {
const response = await fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: data
});
return response.json();
}
postFormData('http://localhost/test', "a=1&b=2")
.then(data => {
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment