Created
May 27, 2015 11:43
-
-
Save SergSlon/4f988ce91782f592f437 to your computer and use it in GitHub Desktop.
serializeFormToObject
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
| $.fn.serializeFormToObject = function() | |
| { | |
| var obj = {}; | |
| var serializedArr = this.serializeArray(); | |
| $.each(serializedArr, function() { | |
| if (obj[this.name] !== undefined) { | |
| if (!obj[this.name].push) { | |
| obj[this.name] = [obj[this.name]]; | |
| } | |
| obj[this.name].push(this.value || ''); | |
| } else { | |
| obj[this.name] = this.value || ''; | |
| } | |
| }); | |
| return obj; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment