JQuery serialized form value conversion to json

Children have a form that he wants to get the content of the form in JSON. Children have tried the following ways.

By $ ("# form"). Serialize () can get the serialized form value string.

 a = 1 & b = 2 & c = 3 & D = 4 & E = 5   


$ (“# form”). SerialIzeaRray () outputs sequence forms in array forms.

[{name: ‘firstname’, value: ‘hello’}, {name: ‘lastname’, value: ‘world’}, {name: ‘alias’ }, // value empty]
All children who don’t satisfy children want JSON. After the stack overflow, I found a method

$. Fn.serializeObject = function () {var o =}; var a = this.serializeArray (); $ .each (a, function () {if (o [this.name]! == undefined) {if (! o [this.name] .push) {o [this.name] = [{THIS.NAME ];} o [this.name] .push (this.Value || ‘);} else {o [this.name] = this.Value ||’ ‘;}}); returno;};
Then pass
$ (“# form”). SerializeObject ();

You can get JSON content. The above is a small series to introduce the jQuery serialized form value to JSON, I hope to help everyone. If you have any questions, please leave a message, the small package will reply to everyone. of. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment