How To Deserialize Params Using JavaScript
erics, Posted May 23rd, 2011 at 1:20:08pm
A very simple deserializer. I am sure it can be streamlined…
Also, note the use of the “while (i–)” construct. This is the best-performing Javascript loop method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var Params = jQuery('#yourForm').serialize(); var yourHash = deserialize(Params); alert(yourHash.yourVariable); function deserialize(Params) { var Data = Params.split("&"); var i = Data.length; var Result = {}; while (i--) { var Pair = decodeURIComponent(Data[i]).split("="); var Key = Pair[0]; var Val = Pair[1]; Result[Key] = Val; } return Result; } |
Julian Toker said on November 16, 2012, 2:06 pm:
Thanks alot for this. I like it :3