Skip to content

Instantly share code, notes, and snippets.

@pomahtuk
Created August 16, 2013 06:25
Show Gist options
  • Save pomahtuk/6247726 to your computer and use it in GitHub Desktop.
Save pomahtuk/6247726 to your computer and use it in GitHub Desktop.
3. Допустим, параметры http-запроса хранятся как свойства объекта. Напишите функцию сериализации параметров в query-строку с добавлением к произвольному url.
var object_to_query = function(object) {
var key, result, value;
if (object == null) {
object = {
"route": "product/product",
"path": "59",
"product_id": "50"
};
}
result = window.location.href + '?';
for (key in object) {
value = object[key];
result += key + '=' + value + '&';
}
return result.substr(0, result.length - 1);
};
object_to_query = (object = {"route":"product/product","path":"59","product_id":"50"}) ->
result = window.location.href + '?'
for key, value of object
result += key + '=' + value + '&'
result.substr(0,result.length-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment