Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios.post & x-www-form-urlencoded & multipart/form-data All In One #112

Open
xgqfrms opened this issue Jul 9, 2021 · 0 comments
Open
Labels
axios.post axios.post FormData FormData URLSearchParams URLSearchParams

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Jul 9, 2021

axios.post & x-www-form-urlencoded & multipart/form-data All In One

🎉 awesome vanilla js solution

URLSearchParams

  1. x-www-form-urlencoded
  const queryString = new URLSearchParams();

  queryString.append('param1', 'value1');
  queryString.append('param2', 'value2');

  axios.post('/foo', queryString);

// test
for(const item of queryString){
    console.log(item);
}

/*

["param1", "value1"]
["param2", "value2"]

*/

FormData

  1. multipart/form-data
  const formData = new FormData();

  formData.append('param1', 'value1');
  formData.append('param2', 'value2');

  axios.post('/foo', formData);

// test
for(const item of formData){
    console.log(item);
}

/*

["param1", "value1"]
["param2", "value2"]

*/
@xgqfrms xgqfrms added FormData FormData URLSearchParams URLSearchParams axios.post axios.post labels Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
axios.post axios.post FormData FormData URLSearchParams URLSearchParams
Projects
None yet
Development

No branches or pull requests

1 participant