Created
August 16, 2013 06:25
-
-
Save pomahtuk/6247726 to your computer and use it in GitHub Desktop.
3. Допустим, параметры http-запроса хранятся как свойства объекта. Напишите функцию сериализации параметров в query-строку с добавлением к произвольному url.
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
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); | |
}; |
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
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