Skip to content

Instantly share code, notes, and snippets.

@brunoscopelliti
Last active December 28, 2015 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brunoscopelliti/7492579 to your computer and use it in GitHub Desktop.
Save brunoscopelliti/7492579 to your computer and use it in GitHub Desktop.
var serialize = function(obj, prefix) {
// http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
var str = [];
for(var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment