Created
July 10, 2013 14:08
-
-
Save rudyryk/5966593 to your computer and use it in GitHub Desktop.
Serialize Javascript object to URL string without [] suffix
This file contains hidden or 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
/* Based on http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object | |
*/ | |
var serializeToURL = function(obj, prefix) { | |
var url = []; | |
for(var p in obj) { | |
var k = prefix ? prefix : p, v = obj[p]; | |
url.push(typeof v == "object" ? | |
serializeToURL(v, k) : | |
encodeURIComponent(k) + "=" + encodeURIComponent(v)); | |
} | |
return url.join("&"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment