Can I easily use jQuery or a plugin of jQuery that serializes the data in a form as a JSON instead of a "text string in standard URL-encoded notation"
Asked
Active
Viewed 223 times
3 Answers
1
Convert form data to JavaScript object with jQuery
The json object can then be represented as string with JSON.stringify() function. For compatibility one can use https://github.com/douglascrockford/JSON-js/blob/master/json2.js

Community
- 1
- 1

FreeCandies
- 1,088
- 10
- 21
1
function serializeToObject(formSerialized)
{
return $.parseJSON("{" + formSerialized.replace(/=/g, ':').replace(/&/g, ',').replace(/([a-z]):/ig, '"$1":') + "}")
}
var object = serializeToObject($('form').serialize())

Joe
- 80,724
- 18
- 127
- 145
-
Nice! But I think one would also have to treat special characters that get encoded somehow, no? – Tom Oct 27 '11 at 21:29