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; } })