Data
The data sent to the server. Will be automatically converted to the request string format. The GET request will be appended to the URL. View the description of the processdata option to disable automatic conversion. It must be in key/value format.
If it is an array, jquery automatically corresponds to the same name for different values. For example, {FOO: ["bar1", "bar2"]} is converted to '& Foo = bar1 & Foo = bar2 '.
Example:
$. Ajax ({type: "Post", URL: "Some. PHP ", data:" name = John & location = Boston ", success: function (MSG) {alert (" data saved: "+ MSG );}});
Here, the parameters following data can be written in two forms: one is to write common URL parameters, and the other is to write them in a JSON array,
The data section in the preceding example can also be written as follows: Data: {name: "John", Location: "Boston "}. What are the differences between the two statements?
Today, I found a slight difference in the usage of the two in development. First, we use the URL to pass the parameter. If the parameter contains the "&" symbol, the parameter may not be received or is incomplete, for example, "data: "Name = John & location = Boston ",",
If the name value is "John & Smith", this may cause a problem. We can escape it using the encodeuricomponent () method in Js,
However, if you use data: {name: "John", Location: "Boston"}, you do not need to escape it. If you escape it, you will receive the escaped string.
Jquery manual description:
Data
The data sent to the server. Will be automatically converted to the request string format. The GET request will be appended to the URL. View the description of the processdata option to disable automatic conversion. It must be in key/value format.
If it is an array, jquery automatically corresponds to the same name for different values. For example, {FOO: ["bar1", "bar2"]} is converted to '& Foo = bar1 & Foo = bar2 '.
Example:
$. Ajax ({type: "Post", URL: "Some. PHP ", data:" name = John & location = Boston ", success: function (MSG) {alert (" data saved: "+ MSG );}});
Here, the parameters following data can be written in two forms: one is to write common URL parameters, and the other is to write them in a JSON array,
The data section in the preceding example can also be written as follows: Data: {name: "John", Location: "Boston "}. What are the differences between the two statements?
Today, I found a slight difference in the usage of the two in development. First, we use the URL to pass the parameter. If the parameter contains the "&" symbol, the parameter may not be received or is incomplete, for example, "data: "Name = John & location = Boston ",",
If the name value is "John & Smith", this may cause a problem. We can escape it using the encodeuricomponent () method in Js,
However, if you use data: {name: "John", Location: "Boston"}, you do not need to escape it. If you escape it, you will receive the escaped string.