0

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"

ref: http://api.jquery.com/serialize/

burnt1ce
  • 14,387
  • 33
  • 102
  • 162

3 Answers3

2

http://api.jquery.com/serializeArray/

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
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