Reputation: 402
I have the following problem:
I have a form and I want to catch the input data. When I want to obtain string, which stores the input from this form, I simply do:
JSON.stringify($('form').serializeArray())
But instead of obtaining string, I would like to have an array with my data (preferably, a serialized array).
How can I solve this problem?
Thanks in advance.
Upvotes: 0
Views: 202
Reputation: 102
Don't stringify the array.
JSON's .serializeArray()
method returns an array of the all the input values in the form
Upvotes: 0
Reputation: 2281
.serializeArray()
creates an array of objects,JSONStringify()
converts it to string
You can use
$( "form" ).submit(function( event ) {
console.log( $( this ).serializeArray() );
event.preventDefault();
});
Upvotes: 1