Created
July 16, 2012 08:59
-
-
Save voronianski/3121670 to your computer and use it in GitHub Desktop.
Custom function serializing object to json
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
/** | |
* Serializing object function | |
*/ | |
$.fn.serializeObject = function() | |
{ | |
var object = {}; | |
var array = this.serializeArray(); | |
$.each(array, function() { | |
if (object[this.name] !== undefined) { | |
if (!object[this.name].push) { | |
object[this.name] = [object[this.name]]; | |
} | |
object[this.name].push(this.value || ''); | |
} else { | |
object[this.name] = this.value || ''; | |
} | |
}); | |
return object; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment