The example in this article describes how jquery passes the JSON-formatted data to the background. Share to everyone for your reference. The specific analysis is as follows:
Before and after data interaction is generally in JSON format, the background can directly convert JSON to entity objects. Convenient for later operation. When jquery passes data to the background, we find that he automatically converts to a query string and does not actually pass in a JSON. And when serializing a form with jquery, the returned format is an array, and further conversion is required. In fact, as long as we configure something in the Ajax method can be done. The code is as follows:
<form id= "ff" >
<input type= "text" name= "test1"/> "<input" type= "
text" name= "Test2
"/> <input type= "text" name= "test3"/> <input type=
"text" name= "test4"/> <input
"button" type= " Save "value=" save "/>
</form>
$ (" #save "). On (" click ", Function () {
var params = $ (" #ff "). Serializearray ();
var j = {};
For (var item in params) {
J[params[item].name] = params[item].value;
}
$.ajax ({
URL: ' index.html ',
data:JSON.stringify (j),
type: ' Post ',
dataType: ' JSON '
, headers:{
Accept: "Application/json",
"Content-type": "Application/json"
},
ProcessData: False,
Cache:false
}). Done (function (data) {
});
If you see a graphic display format in chrome, it means the JSON format is passed in to the background
I hope this article will help you with your jquery programming.