From 06d63e029d941a7993abbfb764237a55715c64da Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 4 Oct 2020 04:19:03 +0200 Subject: Check and debug your code now... --- request-edit.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'request-edit.js') diff --git a/request-edit.js b/request-edit.js index 4d8a245..467a7d0 100644 --- a/request-edit.js +++ b/request-edit.js @@ -22,12 +22,37 @@ function btnAction(action, btn) { if (confirm("Are you sure you want to delete reservation #" + actionData.id + " made by " + actionData.operatorSign + "?")) trDom.remove(); - //var xhr = new XMLHttpRequest(); - //xhr.onreadystatechange = function () { - //if (this.readyState == 4 && status == 200) { - - //} - //}; - //xhr.open("POST", "edit.php", true); - //xhr.send(JSON.stringify(actionData)); + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function () { + if (this.readyState == 4 && status == 200) { + try { + // JSON response to object + var response = JSON.parse(this.responseText); + // Handle various actions + if (response.action == "update") { + document.getElementById("notice").innerHTML = "Record #" + actionData.id + " updated."; + } else if (response.action == "restore") { + trData[1].firstElementChild.checked = response.approved; + trData[2].firstElementChild.innerHTML = response.operatorSign; + trData[3].firstElementChild.innerHTML = response.qso; + trData[4].firstElementChild.innerHTML = response.fromTime; + trData[5].firstElementChild.innerHTML = response.toTime; + trData[6].firstElementChild.innerHTML = response.freqs; + trData[7].firstElementChild.innerHTML = response.modes; + trData[8].firstElementChild.innerHTML = response.specialSign; + trData[9].firstElementChild.innerHTML = response.operatorName; + trData[10].firstElementChild.innerHTML = response.operatorEmail; + trData[11].firstElementChild.innerHTML = response.operatorPhone; + document.getElementById("notice").innerHTML = "Record's #" + actionData.id + " data restored."; + } else if (response.action == "delete") { + document.getElementById("notice").innerHTML = "Record #" + actionData.id + " deleted."; + } + } catch { + console.log(this.responseText); + document.getElementById("notice").innerHTML = "Bad input data!"; + } + } + }; + xhr.open("POST", "edit.php", true); + xhr.send(JSON.stringify(actionData)); } -- cgit v1.2.3