From 323563cedae50dad25c531e90fcda17f9e459feb Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 8 Jul 2019 14:54:52 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day9/task5/static/js/utils.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'day9/task5/static/js/utils.js') diff --git a/day9/task5/static/js/utils.js b/day9/task5/static/js/utils.js index 5d60723..d76c547 100644 --- a/day9/task5/static/js/utils.js +++ b/day9/task5/static/js/utils.js @@ -1,3 +1,31 @@ +const request = { + get: function (url, callback) { + let xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState === 4 && xmlHttp.status === 200) + callback(xmlHttp.responseText); + }; + xmlHttp.open("GET", url, true); + xmlHttp.send(); + }, + + post: function (url, callback, data) { + let xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState === 4 && xmlHttp.status === 200) + callback(xmlHttp.responseText); + }; + xmlHttp.open("POST", url, true); + xmlHttp.send(this.formatParams(data)); + }, + + formatParams: function (params) { + return Object.keys(params).map((key) => { + return key+"="+encodeURIComponent(params[key]) + }).join("&") + } + }; + function elementFromHTML(html) { let elem = document.createElement('div'); elem.innerHTML = html; -- cgit v1.2.3