Refactored code used to sending requests to backends
This commit is contained in:
@@ -111,7 +111,16 @@ function performRequest(endpoint, checkXML, checkTransform){
|
|||||||
empty = true;
|
empty = true;
|
||||||
}
|
}
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
restRequest(endpoint, xmlData, transformData);
|
restRequest(endpoint, xmlData, transformData).then(function(result) {
|
||||||
|
document.getElementById("resultArea").value = result.result;
|
||||||
|
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
|
||||||
|
if (result.status = "OK") {
|
||||||
|
document.getElementById("procinfo").innerText = document.getElementById("procinfo").innerText.concat(" in ", result.time, "ms");
|
||||||
|
procinfo.style.color = "#30aa58";
|
||||||
|
} else {
|
||||||
|
procinfo.style.color = "#aa3030";
|
||||||
|
}
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
document.getElementById("resultArea").value = "No data provided!";
|
document.getElementById("resultArea").value = "No data provided!";
|
||||||
return false;
|
return false;
|
||||||
@@ -129,7 +138,15 @@ function performFormatRequest(endpoint, checkXML){
|
|||||||
empty = true;
|
empty = true;
|
||||||
}
|
}
|
||||||
if (!empty) {
|
if (!empty) {
|
||||||
restRequest(endpoint, xmlData, null);
|
var result = restRequest(endpoint, xmlData, null);
|
||||||
|
document.getElementById("resultArea").value = result.result;
|
||||||
|
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
|
||||||
|
if (response.ok) {
|
||||||
|
document.getElementById("procinfo").innerText = document.getElementById("procinfo").innerText.concat(" in ", result.time, "ms");
|
||||||
|
procinfo.style.color = "#30aa58";
|
||||||
|
} else {
|
||||||
|
procinfo.style.color = "#aa3030";
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
document.getElementById("resultArea").value = "No data provided!";
|
document.getElementById("resultArea").value = "No data provided!";
|
||||||
return false;
|
return false;
|
||||||
@@ -172,21 +189,11 @@ async function restRequest(endpoint, xmlData, transformData) {
|
|||||||
var request = new Request(addr, init);
|
var request = new Request(addr, init);
|
||||||
|
|
||||||
|
|
||||||
|
var result = await fetch(request).then(response => {
|
||||||
await fetch(request).then(response => {
|
return response.text().then(function(text) {
|
||||||
console.log(response.status);
|
return JSON.parse(text);
|
||||||
response.text().then(function (text) {
|
|
||||||
console.log(text);
|
|
||||||
var result = JSON.parse(text);
|
|
||||||
document.getElementById("resultArea").value = result.result;
|
|
||||||
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
|
|
||||||
if (response.ok) {
|
|
||||||
document.getElementById("procinfo").innerText = document.getElementById("procinfo").innerText.concat(" in ", result.time, "ms");
|
|
||||||
procinfo.style.color = "#30aa58";
|
|
||||||
} else {
|
|
||||||
procinfo.style.color = "#aa3030";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user