For school I'm working on a To-Do-List that communicates with a local api my school provided.
I have the GET working, the POST working but the DELETE is not working for me. It's not working at all, I can press the delete button but nothing works.
I wrote this for the DELETE part, I have to give a header because otherwise I get a 415 error. The items I send to the local api get a random ID with the tag "_id".
async function removeItem(id) {
const deleted = await fetch(`http://localhost:3000/${id}`, {
method: "DELETE",
headers: {"Content-Type":"application/json"}
});
}
I have a Delete button with the following code:
async function deleteItem() {
document.getElementById("delete-button").addEventListener("click", removeItem)
renderTodo()
};
The renderToDo function is the function that displays all the items in the database as LI items.
If you guys need more code, just let me know.
Hopefully my question is a bit clear, I'm fairly new to developing.
Thanks in advance.