Ajax form submission with payload submission

Source: Internet
Author: User

When the backend processes the data submitted by the front-end, you can either use form parsing or use JSON to parse the payload string.

Form parsing can get request parameters directly from the requests object, so that object conversion and processing is relatively easy, but when large chunks of JSON data need to be submitted, there may be a lot of data splitting and processing work, in addition to the collection type of processing, but also its weak place.

The advantage of payload is that a large number of JSON strings can be submitted at one time, but it is not possible to get parameters from request, but also to be limited to the depth of JSON parsing (especially with multi-layered object cascade, the lowest object can hardly be converted to concrete type).

In the case of Chrome, the network parameters they submit are as follows:

Form Submission Method:

Here's how payload is submitted:

specifically to the implementation, $.ajax default implementation is the form submission, the core lies in the ContentType settings, as follows:

vardata ={name:'ABC'};//Submit Data$.ajax ('app/', {method:'POST',    //encode data into form modeContentType:'application/x-www-form-urlencoded; Charset=utf-8',    //The data must be a JS object, not a stringData:data, Success:function (datas) {Console.log (datas)}})

The implementation of the payload submission method is as follows:

$.ajax ('app/', {    //as far as I have tested, payload can only be used for post modeMethod'POST',    //The data type must be a type other than application/x-www-form-urlencodedContentType:'Application/json;charset=utf-8', charset=utf-8',    //data must be converted to a stringdata:JSON.stringify (data), Success:function (datas) {Console.log (datas)}})

Ajax form submission with payload submission

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.