IP_Zhelovanov/front/MyScript.js

50 lines
1.2 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;
let type = document.getElementById("type").value;
console.log("a" + num1 + "b" + num2)
fetch(`http://localhost:8080/${address}?a=${num1}&b=${num2}&type=${type}`)
.then(response => {
return response.text();
})
.then(result => {
setResult(result);
})
}
function executeRequestArray(address) {
let array = document.getElementById("enterArray").value;
fetch(`http://localhost:8080/${address}?InputNumbers=${array}&type=${type}`)
.then(response => {
return response.json();
})
.then(result => {
setResult(result);
})
}