Created
July 10, 2012 13:15
-
-
Save bor/3083170 to your computer and use it in GitHub Desktop.
jQuery plugin: add .serializeObject() method to jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery plugin: add .serializeObject() method to jQuery | |
// at this moment (jQuery v1.7.2) where no such method in core | |
// this method serializes a form into an (arguably more useful) object | |
(function($,undefined) { | |
$.fn.serializeObject = function() { | |
var obj = {}; | |
$.each( this.serializeArray(), function(i,o) { | |
obj[o.name] = obj[o.name] === undefined ? o.value : | |
$.isArray( obj[o.name] ) ? obj[o.name].concat( o.value ) : | |
[ obj[o.name], o.value ]; | |
}); | |
return obj; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment