Фронт
This commit is contained in:
parent
2c6869c6db
commit
6078dda39e
67
index.html
Normal file
67
index.html
Normal file
@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru-ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-sm p-3">
|
||||
<form id="plus">
|
||||
<h2 class="text-center mb-3">Plus</h2>
|
||||
<div class="mb-3">
|
||||
<div class="input-group mb-1">
|
||||
<input id="value1plus" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
||||
<span class="input-group-text">+</span>
|
||||
<input id ="value2plus" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
||||
<span class="input-group-text" id="plus_result">0</span>
|
||||
<button id = "buttonplus" type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form id="minus">
|
||||
<h2 class="text-center mb-3">Minus</h2>
|
||||
<div class="mb-3">
|
||||
<div class="input-group mb-1">
|
||||
<input id = "value1minus" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
||||
<span class="input-group-text">-</span>
|
||||
<input id = "value2minus" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
||||
<span class="input-group-text" id="minus_result">0</span>
|
||||
<button id = "buttonminus" type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form id="mult">
|
||||
<h2 class="text-center mb-3">Mult</h2>
|
||||
<div class="mb-3">
|
||||
<div class="input-group mb-1">
|
||||
<input id = "value1mult" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
||||
<span class="input-group-text">*</span>
|
||||
<input id = "value2mult" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
||||
<span class="input-group-text" id="mult_result">0</span>
|
||||
<button id = "buttonmult" type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form id="div">
|
||||
<h2 class="text-center mb-3">Del</h2>
|
||||
<div class="mb-3">
|
||||
<div class="input-group mb-1">
|
||||
<input id="value1div" type="number" class="form-control" placeholder="V1" aria-label="First Number" name="v1" autocomplete="off">
|
||||
<span class="input-group-text">/</span>
|
||||
<input id = "value2div" type="number" class="form-control" placeholder="V2" aria-label="Second Number" name="v2" autocomplete="off">
|
||||
<span class="input-group-text" id="div_result">0</span>
|
||||
<button id = "buttondiv" type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="module" src="main.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
</body>
|
||||
</html>
|
27
main.js
Normal file
27
main.js
Normal file
@ -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;
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user