Skip to content

Instantly share code, notes, and snippets.

@davetayls
Created November 17, 2011 11:40
Show Gist options
  • Select an option

  • Save davetayls/1372969 to your computer and use it in GitHub Desktop.

Select an option

Save davetayls/1372969 to your computer and use it in GitHub Desktop.
jQuery.serializeObject
/**
jQuery.serializeObject
http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery/1186309#1186309
*/
/*jslint browser: true, vars: true, white: true, forin: true */
/*global define,require */
(function($){
'use strict';
$.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;
};
}(window.jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment