Advertisement
stuppid_bot

build query string

Sep 23rd, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buildQuery(params) {
  2.   if (!isPlainObject(params)) {
  3.     return null;
  4.   }
  5.   function build(data, name) {
  6.     var result = [];
  7.     for (var key in data) {
  8.       if (data.hasOwnProperty(key)) {
  9.         var value = data[key];
  10.         key = encodeURIComponent(key);
  11.         if (name) {
  12.           key = name + '[' + key + ']';
  13.         }
  14.         if (isPlainObject(value) || isArray(value)) {
  15.           result.push(arguments.callee(value, key));
  16.         } else {
  17.           result.push(key + '=' + encodeURIComponent(value));
  18.         }
  19.       }
  20.     }
  21.    return result.join('&');
  22.   }
  23.   return build(params);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement