Skip to content

Instantly share code, notes, and snippets.

@i11v
Last active December 10, 2015 01:38
Show Gist options
  • Save i11v/4359945 to your computer and use it in GitHub Desktop.
Save i11v/4359945 to your computer and use it in GitHub Desktop.
This function extends jQuery by serializeObject method. Argument — form data, returns object.
;(function ($) {
$.fn.serializeObject = function () {
var obj = {},
arr = this.serializeArray();
$.each(arr, function () {
if (typeof 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;
};
}(jQuery || {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment