Skip to content

Instantly share code, notes, and snippets.

@dshaw
Created June 22, 2010 20:46
Show Gist options
  • Save dshaw/449041 to your computer and use it in GitHub Desktop.
Save dshaw/449041 to your computer and use it in GitHub Desktop.
$.fn.serializeObject()
// Flattens the Array produced by .serializeArray() into an Object
// with names as keys and values as their values.
(function($) {
$.fn.serializeObject = function() {
var formData = this.serializeArray(),
data = {};
for (var i=0, len=formData.length; i<len; i++) {
data[formData[i].name] = formData[i].value;
}
return data;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment