Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/a42e03a7a09cc4635ad7 to your computer and use it in GitHub Desktop.
Save nczz/a42e03a7a09cc4635ad7 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