querystring serializer
MyClass.prototype.serialize = function(obj, prefix) {
var _temp = [];
for(var p in obj) {
if(typeof obj[p] == "function") continue;
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
_temp.push(typeof v == "object" ?
this.serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
return _temp.join("&").replace(/\s/gi,'');
}
// usage:
myObj = new MyClass();
myObj.serialize({k1:"v1", "k2":{k2_1:"v2_1"}});Written by Luca Simonetti
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Serialize
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#