IP_Zhelovanov/front/MyScript.js

48 lines
1.1 KiB
JavaScript

function setResult(result) {
let lbl = `<label class="bg-success">Ответ:${result}</label>`;
document.getElementById("result").innerHTML = lbl;
}
function add(){
executeRequest("add");
}
function sub(){
executeRequest("sub");
}
function mul(){
executeRequest("mul");
}
function del(){
executeRequest("del");
}
function enterArray(){
executeRequestArray("array");
}
function executeRequest(address) {
let num1 = document.getElementById("addNum1").value;
let num2 = document.getElementById("addNum2").value;
console.log("a" + num1 + "b" + num2)
fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}`)
.then(response => {
return response.json();
})
.then(result => {
setResult(result);
})
}
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);
})
}