Skip to content

Instantly share code, notes, and snippets.

@SergSlon
Created May 27, 2015 11:43
Show Gist options
  • Select an option

  • Save SergSlon/4f988ce91782f592f437 to your computer and use it in GitHub Desktop.

Select an option

Save SergSlon/4f988ce91782f592f437 to your computer and use it in GitHub Desktop.
serializeFormToObject
$.fn.serializeFormToObject = function()
{
var obj = {};
var serializedArr = this.serializeArray();
$.each(serializedArr, function() {
if (obj[this.name] !== undefined) {
if (!obj[this.name].push) {
obj[this.name] = [obj[this.name]];
}
obj[this.name].push(this.value || '');
} else {
obj[this.name] = this.value || '';
}
});
return obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment