From 6078dda39e6bce9de2db1b5b01e3905b11f1777a Mon Sep 17 00:00:00 2001 From: Pineapple Date: Mon, 3 Apr 2023 12:41:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.js | 27 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 index.html create mode 100644 main.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..879d7f0 --- /dev/null +++ b/index.html @@ -0,0 +1,67 @@ + + + + + + Vite App + + +
+
+

Plus

+
+
+ + + + + 0 + +
+
+
+ +
+

Minus

+
+
+ + - + + 0 + +
+
+
+ +
+

Mult

+
+
+ + * + + 0 + +
+
+
+ +
+

Del

+
+
+ + / + + 0 + +
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..c72520e --- /dev/null +++ b/main.js @@ -0,0 +1,27 @@ +const xhr = new XMLHttpRequest () + +const get = (operation, value1, value2) =>{ + + return new Promise((resolve, reject) => { + xhr.open('GET', `http://localhost:8080/${operation}?val1=${value1}&val2=${value2}`) + + xhr.onload = () => { + if(xhr.status == 200) resolve(xhr.response) + else reject(xhr.response) + } + + xhr.send() + }) +} + +document.querySelectorAll("form").forEach((item) => { + item.onsubmit = async (e) => { + e.preventDefault(); + const form = e.target; + const val1 = form.v1.value; + const val2 = form.v2.value; + + const responce = await get(form.id, val1, val2); + document.getElementById(`${form.id}_result`).innerHTML = responce; + } +}) \ No newline at end of file