-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (33 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
35 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function sendRequest(url, retriesLeft) {
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
const response = JSON.parse(this.responseText);
if(response == "error"){
document.getElementById("result").innerHTML = "Error: Failed to send request.";
}
else{
document.getElementById("result").innerHTML = "tg(F(x)) = "+ response;
}
} else if (retriesLeft > 0) {
setTimeout(() => {
sendRequest(url, retriesLeft - 1);
}, 1000);
} else {
document.getElementById("result").innerHTML = "Error: Failed to send request.";
}
}
};
xhttp.open("GET", url);
xhttp.send();
}
function returnValue() {
let func_v = document.getElementById("func_s").value;
let point_v = document.getElementById("point_v").value;
point_v = parseInt(point_v);
const encoded_func_v = encodeURIComponent(func_v);
const port = document.getElementById("server_port").value;
const url = `http://localhost:${port}/api_?func_v=${encoded_func_v}&point_v=${point_v}`;
sendRequest(url, 4);
}