Created
May 6, 2013 05:28
-
-
Save juliengrimault/5523508 to your computer and use it in GitHub Desktop.
Revisions
-
juliengrimault created this gist
May 6, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ (function ($) { $.fn.serializeJSON = function () { var json = {} var form = $(this); form.find('input, select').each(function () { var val if (!this.name) return; if ('radio' === this.type) { if (json[this.name]) { return; } json[this.name] = this.checked ? this.value : ''; } else if ('checkbox' === this.type) { val = json[this.name]; if (!this.checked) { if (!val) { json[this.name] = ''; } } else { json[this.name] = typeof val === 'string' ? [val, this.value] : $.isArray(val) ? $.merge(val, [this.value]) : this.value; } } else { if (this.value != "") { json[this.name] = this.value; } } }) return json; } })(jQuery)