Created
May 19, 2011 05:07
-
-
Save kilork/980229 to your computer and use it in GitHub Desktop.
toUriParameter
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
| function toUriParameter(obj, post) { | |
| var key, value, | |
| parts = [], | |
| encode = post ? function(s) { | |
| return window.encodeURIComponent(s).replace(/%20/g,'+'); | |
| } : window.encodeURIComponent, | |
| iterator = function(item) { | |
| parts.push(encode(key) + '=' + encode(item)); | |
| }; | |
| for (key in obj) { | |
| if (obj.hasOwnProperty(key)) { | |
| value = obj[key]; | |
| if (value instanceof Array) { | |
| value.forEach(iterator); | |
| } else { | |
| parts.push(encode(key) + '=' + encode(value)); | |
| } | |
| } | |
| } | |
| return parts.join('&'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment