Axios send a POST request to submit form data
By default, Axios serializes JavaScript objects into JSON. To send data in application/x-www-form-urlencoded format, you can use one of the following options.
1. Browser. In the browser, you can use the Urlsearchparams API as follows:
var params = new Urlsearchparams ();p arams.append (' param1 ', ' value1 ');p arams.append (' param2 ', ' value2 '); Axios.post ('/ Foo ', params);
Please note that not all browsers support Urlsearchparams (see caniuse.com), but you can use Polyfill. Alternatively, you can encode data using the QS Library:
var qs = require (' qs '); Axios.post ('/foo ', qs.stringify ({' Bar ': 123}));
2. Node. js. In node. js, you can use the QueryString module as follows:
var querystring = require (' querystring '); Axios.post (' http://something.com/', querystring.stringify ({foo: ' Bar '}));
You can also use the QS Library.
Resources:
- Https://www.npmjs.com/package/axios
- Https://stackoverflow.com/questions/29136374/what-the-difference-between-qs-and-querystring
Axios send a POST request, how do I submit the form data?