diff options
author | Mateja <mail@matejamaric.com> | 2020-10-04 04:19:03 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-10-04 04:19:03 +0200 |
commit | 06d63e029d941a7993abbfb764237a55715c64da (patch) | |
tree | 12fb5891158894c3f94004431efcfc6fba5e66cc /request-edit.js | |
parent | 9bcdc348dc9e93440e1cb5067548241259750cef (diff) | |
download | old-php-yota-06d63e029d941a7993abbfb764237a55715c64da.tar.gz old-php-yota-06d63e029d941a7993abbfb764237a55715c64da.zip |
Check and debug your code now...
Diffstat (limited to 'request-edit.js')
-rw-r--r-- | request-edit.js | 41 |
1 files changed, 33 insertions, 8 deletions
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)); } |