Skip to content

Instantly share code, notes, and snippets.

@sabahtalateh
Created January 16, 2017 11:32
Show Gist options
  • Save sabahtalateh/728d5fb7483c0d8cb3e92a574c78b2ed to your computer and use it in GitHub Desktop.
Save sabahtalateh/728d5fb7483c0d8cb3e92a574c78b2ed to your computer and use it in GitHub Desktop.
JS Serialise object
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment