Have you tried "serializeArray"? This gives you an array of names and values. You can turn this into an object if you want:
var paramObj = {}; $.each($('#myForm').serializeArray(), function(_, kv) { paramObj[kv.name] = kv.value; });
(I need to check again what jQuery does with arrays, I think it encodes them as Javascript array values, but I'm not 100% sure.)
there is no change ah, it does not set multivalued parameters in the form of arrays - you get repetitions with the same name. So the make-object code should look like this:
var paramObj = {}; $.each($('#myForm').serializeArray(), function(_, kv) { if (paramObj.hasOwnProperty(kv.name)) { paramObj[kv.name] = $.makeArray(paramObj[kv.name]); paramObj[kv.name].push(kv.value); } else { paramObj[kv.name] = kv.value; } });
(or something like that, maybe a little squeeze).
Pointy Mar 08 '10 at 17:21 2010-03-08 17:21
source share