Skip to content

Instantly share code, notes, and snippets.

@jaf0
Forked from jonmaim/qs.js
Created August 1, 2014 15:32
Show Gist options
  • Save jaf0/e919cc780848811ec480 to your computer and use it in GitHub Desktop.
Save jaf0/e919cc780848811ec480 to your computer and use it in GitHub Desktop.
/* Converts an object into a key/value par with an optional prefix. Used for converting objects to a query string */
var qs = function(obj, prefix){
var str = [];
for (var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p,
v = obj[p];
str.push(angular.isObject(v) ? qs(v, k) : (k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment