Axios send a POST request, how do I submit the form data?

Source: Internet
Author: User

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:
    1. Https://www.npmjs.com/package/axios
    2. Https://stackoverflow.com/questions/29136374/what-the-difference-between-qs-and-querystring

Axios send a POST request, how do I submit the form data?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.