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