Vue:axios of Post requests in the

Source: Internet
Author: User

Vue's Ajax request uses the Axios component, which results in the backend (Python language +django framework) not receiving when it uses the POST request and discovers that it is transmitting data to the background.

The request.body in the background shows that what I'm transmitting is that data was bundled into a key value in obj by Django, and value is an empty array. Causes the background to be fetched.

Solution:

Axios ({    method: ' POST ',    url:ap_service_url+opt.url,    data:opt.obj,    transformrequest: [Function (  Data) {Let            ret = "for" Let            it in data) {ret + =                encodeURIComponent (it) + ' = ' + encodeURIComponent (Data[it]) + ' & '            return ret        }],    headers:{' content-type ': "Application/x-www-form-urlencoded"}}). Then (function (res) {/      * request succeeds */}). catch (function (err) {/       * request failed */})

Successfully jump out of this pit by adding transformrequset ~

Vue:axios of Post requests in the

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.