How to submit multiple sets of identical data (arrays) to the background with Ajax?

Source: Internet
Author: User

I wrote this in Ajax.

$ ("#subbutton"). Click (function () {
var machinecode_1=$ ("#machineCode_1"). Val ();
var machinecode_2=$ ("#machineCode_2"). Val ();
var machinecode_3=$ ("#machineCode_3"). Val ();
var machinecode_4=$ ("#machineCode_4"). Val ();
var machinecode_5=$ ("#machineCode_5"). Val ();
$.ajax ({
Type: "POST",
ContentType: "Application/json",
URL: "./system/dealer_addallmachcode",
Data: {machinearr: ([Machinecode_1,machinecode_2,machinecode_3,machinecode_4,machinecode_5]). Join (";")},
DataType: ' JSON ',
Success:function (Result) {
Alert ("Increased success");
}
});
});

Background SSM framework: Machinearr and get Set

Debug report NULL pointer error

Machinearr no data. Later after looking for inquiries to find the cause of the error, Application/json need to change to

application/x-www-form-urlencoded, but why did I check out their differences?
Application/json:application/json is the MIME type returned in the background, not the way the foreground submits. application/x-www-form-urlencoded: Form data is encoded as a name/value pair。 This is the standard encoding format. multipart/form-data: The form data is encoded as a message, and each control on the page corresponds to a part of the message。 Text/plain: Form data is encoded in plain text with no control or formatting characters.

The Enctype property of a form is encoded in two common ways: application/x-www-form-urlencoded and Multipart/form-data, which are application/by default. X-www-form-urlencoded. When action is get, the browser uses x-www-form-urlencoded encoding to convert the form data into a string (name1=value1& amp;name2=value2 ... ), and then append the string to the URL, using the. Split, to load the new URL. When the action is post, the browser encapsulates the form data into the HTTP body and then sends it to the server. If you don't have a type=file control, you can use the default application/x-www-form-urlencoded. But if you have type=file, you will need to use Multipart/form-data. The browser splits the entire form into units of controls and adds Content-disposition (form-data or file) to each section, Content-type (default = Text/plain), name (control name), and so on. and add the separator (boundary).

Summary: Client-submitted contenttype can only be application/x-www-form-urlencoded or multipart/form-data, and binary data uses multiple encodings. The preceding default encoding is the string, which is the file. But if you download from the server, the code is many, such as you say Application/json,text/plan,application/image ... All can be.

How to submit multiple sets of identical data (arrays) to the background with Ajax?

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.