Created
November 17, 2011 11:40
-
-
Save davetayls/1372969 to your computer and use it in GitHub Desktop.
jQuery.serializeObject
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.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