diff options
author | LarsVomMars | 2021-01-31 17:50:55 +0100 |
---|---|---|
committer | LarsVomMars | 2021-01-31 17:50:55 +0100 |
commit | 0dd2e9da3880ca47bc9c3970d6d82565c94922f6 (patch) | |
tree | c63018c1ef1c7bc1126741eca720dfd2f991e3a2 /profile | |
parent | 434818de1de3cfa41b21fbc4b59bc0183339335a (diff) |
Little POST/PUT mixup
Diffstat (limited to 'profile')
-rw-r--r-- | profile/public/user.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/profile/public/user.js b/profile/public/user.js index 22d31cc..93d1399 100644 --- a/profile/public/user.js +++ b/profile/public/user.js @@ -3,6 +3,8 @@ const userDiv = document.getElementById("user"); const commentsDiv = document.getElementById("comments"); const charDiv = document.getElementById("char"); +let charMethod = "POST"; + if (uid < 1 || uid > 119) window.location.assign("./users.html"); // Well async function addUser(userData) { @@ -160,7 +162,6 @@ async function addComments(comments) { } function addChar(char) { - let method = "POST"; const h2 = document.createElement("h2"); h2.textContent = "Erkennungsmerkmal"; h2.addEventListener("click", (evt) => { @@ -177,7 +178,7 @@ function addChar(char) { btn.textContent = "Senden"; if (char.hasOwnProperty("txt")) { - method = "PUT"; + charMethod = "PUT"; inp.value = char.txt; } @@ -186,11 +187,13 @@ function addChar(char) { btn.addEventListener("click", async (e) => { const char = inp.value; const body = JSON.stringify({ char }); - await fetch(`api/char/${uid}`, { - method, + const resp = await fetch(`api/char/${uid}`, { + method: charMethod, headers: { "Content-Type": "application/json" }, body, }); + const res = await resp.json(); + if (res.success) charMethod = "PUT"; alert("Okidoki, danke!"); }); const div = document.createElement("div"); |