summaryrefslogtreecommitdiff
path: root/day9/task5/static/js/utils.js
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-07-08 14:54:52 +0400
committerAndrew <saintruler@gmail.com>2019-07-08 14:54:52 +0400
commit323563cedae50dad25c531e90fcda17f9e459feb (patch)
tree59447bf09de6aec82ab426513ff2e9ae1ee815e5 /day9/task5/static/js/utils.js
parentd48c3ccb5e273730d2643366ecd6aa0dcb22e6f4 (diff)
Исправлен код изменения значения полей.
Diffstat (limited to 'day9/task5/static/js/utils.js')
-rw-r--r--day9/task5/static/js/utils.js28
1 files changed, 28 insertions, 0 deletions
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;