Created
October 2, 2016 13:18
-
-
Save dead23angel/f5d8662fbf821fe8394bc0fb2d0b8323 to your computer and use it in GitHub Desktop.
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
encodeQueryFromArgs: function(args) { | |
console.log(args); | |
var result="?", counter = 1; | |
// create enconded URL from args | |
for (var key in args) { | |
var keyValue = ""; | |
if ( args[key] instanceof Array ) { | |
/* | |
* We are dealing with an array in the query string ?key=Value0&key=Value1 | |
* That a REST application translates into key=[Value0, Value1] | |
*/ | |
for ( var ii=0, sizeArray = args[key].length; ii < sizeArray; ii++ ) { | |
result = result.concat((counter > 1 ? "&": "") + key + "=" + encodeURIComponent(args[key][ii])); | |
counter++; | |
} | |
} else { //No array, just a single &key=value | |
keyValue = key + "=" + encodeURIComponent(args[key]); | |
result = result.concat((counter > 1 ? "&":"") + keyValue); | |
} | |
counter++; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment