Skip to content

Instantly share code, notes, and snippets.

@dead23angel
Created October 2, 2016 13:18
Show Gist options
  • Save dead23angel/f5d8662fbf821fe8394bc0fb2d0b8323 to your computer and use it in GitHub Desktop.
Save dead23angel/f5d8662fbf821fe8394bc0fb2d0b8323 to your computer and use it in GitHub Desktop.
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