I'm using a fetch request with the PUT method and giving a body but when I call the endpoint that I defined on my server page, I keep getting undefined.
Does anyone know why?
Here's where the call comes from:
<tr>
<td><%= index %></td>
<td class="editable" id="item">
<%= item %>
</td>
<td class="editable" id="desc">
<%= desc %>
</td>
<td class="editable" id="status">
<%= status %>
</td>
<td class="editable" id="priority">
<%= priority %>
</td>
<td><button id="delete-button">Delete</button>
<button onclick="refetch(this)">Edit</button>
</td>
</tr>
<script>
async function refetch(btn) {
if (btn.innerHTML === 'Edit') {
await fetch('http://localhost:3000/todo', {
method: 'PUT',
body: {
edit: 'true'
}
})
}
}
</script>
And my endpoint:
app.put("/todo", (req, res) => {
console.log(req.body);
});