Ajax post method form submission setRequestHeader error Solution

Source: Internet
Author: User

Ajax post method form submission setRequestHeader error Solution

When we create an asynchronous object XMLHttpRequest and transmit data to the background in the post mode at the same time.

Set the value of the xhr. setRequestHeader Member of the asynchronous object

XMLHttpRequest. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); otherwise, the backend cannot receive the value passed in. It is shown in Google's compiler that the transfer value is in Request Payload. This is incorrect () -- check the attribute.

The correct method is in Form Data ()

This setting specifies how to encode the form data before it is sent to the server. There are three forms, which can be found in w3c documentation,

Example: <form enctype = "application/x-www-form-urlencoded"> </form>

 

There is a method serialize () in jquery .. The parameter can be set to a nest. Change to & name = "value"

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.