Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created August 20, 2012 21:47
Show Gist options
  • Save elijahmanor/3408190 to your computer and use it in GitHub Desktop.
Save elijahmanor/3408190 to your computer and use it in GitHub Desktop.
Serialize Form Into Object
//Uses jQuery's serialize form method & then transforms data into an object
var data = {};
$.each( $( "#Form" ).serialize().split( "&" ), function( index, item ) {
var keyValue = item.split( "=" );
data[ keyValue[ 0 ] ] = decodeURIComponent( keyValue[ 1 ] ).replace( /\+/g, " " );
});
console.log( JSON.stringify( data, null, 4 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment