IP_Zhelovanov/front/MyScript.js

48 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-02-20 22:25:28 +04:00
function setResult(result) {
let lbl = `<label class="bg-success">Ответ:${result}</label>`;
document.getElementById("result").innerHTML = lbl;
}
2023-03-04 16:27:44 +04:00
2023-02-20 22:25:28 +04:00
function add(){
2023-03-04 16:27:44 +04:00
executeRequest("add");
2023-02-20 22:25:28 +04:00
}
2023-03-04 16:27:44 +04:00
2023-02-20 22:25:28 +04:00
function sub(){
2023-03-04 16:27:44 +04:00
executeRequest("sub");
2023-02-20 22:25:28 +04:00
}
2023-03-04 16:27:44 +04:00
2023-02-20 22:25:28 +04:00
function mul(){
2023-03-04 16:27:44 +04:00
executeRequest("mul");
2023-02-20 22:25:28 +04:00
}
2023-03-04 16:27:44 +04:00
function del(){
executeRequest("del");
2023-02-20 22:25:28 +04:00
}
2023-03-04 16:27:44 +04:00
function enterArray(){
executeRequestArray("array");
}
2023-02-20 22:25:28 +04:00
2023-03-04 16:27:44 +04:00
function executeRequest(address) {
let num1 = document.getElementById("addNum1").value;
let num2 = document.getElementById("addNum2").value;
2023-02-20 22:25:28 +04:00
console.log("a" + num1 + "b" + num2)
fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`)
.then(response => {
return response.json();
})
.then(result => {
setResult(result);
})
2023-03-04 16:27:44 +04:00
}
function executeRequestArray(address) {
let array = document.getElementById("enterArray").value;
fetch(`http://localhost:8080/${address}?InputNumbers=${array}`)
.then(response => {
return response.json();
})
.then(result => {
setResult(result);
})
2023-02-20 22:25:28 +04:00
}