Reputation: 3406
Is it possible to deserialize the result of jQuery.Serialize to an array (or other similar JavaScript data structure)?
I know about the jQuery.Deserialize plugin but I don't think you can get the deserialized data; i.e., it is for deserializing back to the original form (from which you previously serialized the data).
Upvotes: 0
Views: 4505
Reputation: 360
Try using this syntax, Hope It will help you.
var d = $('#form4').serializeArray();
d.push({lead_id : $("#lead_id").val()});
Upvotes: 0
Reputation: 25165
As @SpiXel has shown you can use serializeArray
to generate an array from a <form>
element.
There is no function available in jQuery to convert the string generated by serialize
function. You have to do something as shown below
var paramString = $("#cform").serialize();
var jsonString = '{"' + paramString.replace(/[&=]/g, function(a, b) {
return (a == "&" ? ",\"" : "\":");
}) + '}';
var object = $.parseJSON(jsonString);
Upvotes: 0
Reputation: 4516
If You want it as an array , try using serializeArray instead of serialize, that gives you the elements mapped to their names as an associative array.
Upvotes: 1