Last active
December 28, 2015 11:19
-
-
Save brunoscopelliti/7492579 to your computer and use it in GitHub Desktop.
Querystring encoding of a javascript object.
More @ http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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