Skip to content

Instantly share code, notes, and snippets.

@gustavonovaes
Created May 22, 2016 15:19
Show Gist options
  • Save gustavonovaes/2c282e7d2f1c19bd66141af83d8f9df2 to your computer and use it in GitHub Desktop.
Save gustavonovaes/2c282e7d2f1c19bd66141af83d8f9df2 to your computer and use it in GitHub Desktop.
Make a form data object
jQuery.fn.extend({
serializeJSON: function () {
var data = {};
this.map(function () {
var elements = jQuery.prop(this, "elements");
return elements ? jQuery.makeArray(elements) : this;
})
.filter(function () {
return this.name && !jQuery(this).is(":disabled");
})
.each(function () {
data[this.name] = this.value;
});
return data;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment