Refactored code used to sending requests to backends
This commit is contained in:
		| @@ -111,7 +111,16 @@ function performRequest(endpoint, checkXML, checkTransform){ | ||||
|         empty = true; | ||||
|     } | ||||
|     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{ | ||||
|         document.getElementById("resultArea").value = "No data provided!"; | ||||
|         return false; | ||||
| @@ -129,7 +138,15 @@ function performFormatRequest(endpoint, checkXML){ | ||||
|             empty = true; | ||||
|     } | ||||
|     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{ | ||||
|         document.getElementById("resultArea").value = "No data provided!"; | ||||
|         return false; | ||||
| @@ -172,21 +189,11 @@ async function restRequest(endpoint, xmlData, transformData) { | ||||
|     var request = new Request(addr, init); | ||||
|  | ||||
|      | ||||
|  | ||||
|     await fetch(request).then(response => { | ||||
|         console.log(response.status); | ||||
|         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"; | ||||
|             } | ||||
|     var result = await fetch(request).then(response => { | ||||
|         return response.text().then(function(text) { | ||||
|             return JSON.parse(text); | ||||
|         }); | ||||
|  | ||||
|          | ||||
|     }); | ||||
|     return result; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user