When using jquery for Ajax coding, these 3 APIs are often used, and this article learns how to use the 3 APIs. such as the next HTML fragment, if we submit the control value under the holder form to the server. You need to use serialize or Serializearray.
<form id= "Holder" > <input type= "text" Name= "a" value= "1"/> <div><input type= "text" name = "B" value= "2" id= "B"/> </div> <input type= "hidden" name= "C" value= "3" id= "C"/> <div > <input type= "checkbox" Name= "F" value= "8" checked= "true"/> <input type= "checkbox" Name= "F" Value= "9" checked= "true"/> </div></form>
$ ("#holder"). Serialize () The output is a=1&b=2&c=3&f=8&f=9
$ ("#holder"). The Serializearray () output results are as follows:
[ {name: ' A ', Value: ' 1 '}, {name: ' B ', Value: ' 2 '}, {name: ' C ', Value: ' 3 '}, {name: ' F ', Value: ' 8 '}, {name: ' F ', Value: ' 9 '}]
As you can see: bothserialize and Serializearray operate on the jquery object (the selected form element), but the return value format is different.
It is important to note here: These 2 APIs can only manipulate the form, and if you change the holder to a div, you will find that it does not work.
var obj = {"A": {one:1,two:2,three:3}, "B": [1,2,3]};var recursiveencoded = $.param (obj); var recursivedecoded = Decodeur IComponent ($.param (obj)); alert (recursiveencoded); alert (recursivedecoded);
The output is:
a%5bone%5d=1&a%5btwo%5d=2&a%5bthree%5d=3&b%5b%5d=1&b%5b%5d=2&b%5b%5d=3a[one]=1&a[two]= 2&a[three]=3&b[]=1&b[]=2&b[]=3
You can see that when you use Param to convert JSON to HTML parameters, special characters are encoded. For JavaScript coding, refer to this article.
The return of the recursivedecoded shows that the serialization of the Param array is not the result we want. You can use regular expression conversions:
Recursivedecoded.replace (/\[\]/g, "")
JQuery Ajax Operations Common Api:serializearray, serialize, param differences and use