From : 1190000000473625
The child has a form that he wants to get to the contents of the form in JSON. The children tried the following ways.
Through $ ("#form"). Serialize () can get a serialized form value string.
a=1&b=2&c=3&d=4&e=5
The form value is serialized as an array by $ ("#form"). Serializearray () output.
[ ‘firstname‘, value: ‘Hello‘}, {name: ‘lastname‘, value: ‘World‘}, {name: ‘alias‘}, // 值为空]
Nothing satisfies the child's desire to want JSON. After the stack overflow, a method was found
$.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] = [o[ this.name]]; } o[this.name].push (this.value | | else {o[this.name] = this.value || return o;
Then JSON.stringify($("#form").serializeObject());
you can get the JSON content by the chatter.
Convert jquery serialized form values to JSON