Skip to content

Instantly share code, notes, and snippets.

@weishai
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weishai/ca3fca0e701691393dbf to your computer and use it in GitHub Desktop.
Save weishai/ca3fca0e701691393dbf to your computer and use it in GitHub Desktop.
serialize Object for Form
$.fn.serializeObject = function() {
var o = Object.create(null),
elementMapper = function(element) {
element.name = $.camelCase(element.name);
return element;
},
appendToResult = function(i, element) {
var node = o[element.name];
if ('undefined' != typeof node && node !== null) {
o[element.name] = node.push ? node.push(element.value) : [node, element.value];
} else {
o[element.name] = element.value;
}
};
$.each($.map(this.serializeArray(), elementMapper), appendToResult);
return o;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment