하기와 같이 코딩시 왜 삭제가 안되는지 이유를 모르겠습니다 ㅠㅠ 새로고침 오지게 누르니까 3번아이디를 가진 게시물은 삭제가 되었는데
이후로는 터미널에
위이이이잉 mongoDB연결 완료
{}
삭제완료
이게 출력되면서 삭제가 안됩니다 ㅠㅠ
아 제이쿼리 밑에 스크립트 태그 열었습니다 답변 해주세요 ㅠㅠ
//데이터 삭제 요청
app.delete('/delete', function(요청, 응답){
console.log(요청.body)
요청.body._id = parseInt(요청.body._id)
//요청.body에 담겨온 게시물번호를 가진 글을 db에서 찾아서 삭제해주세요
db.collection('post').deleteOne(요청.body, function(에러, 결과){
console.log('삭제완료')
})
});
-----------------
<!-- 서버에서 가져온 할 일 리스트 -->
<ul class="list-group">
<% for (var i = 0; i<posts.length; i++){ %>
<li class="list-group-item">
<h4 class="title">할 일 제목 : <%= posts[i].제목 %></h4>
<p>할 일 마감남짜 : <%= posts[i].날짜 %></p>
<button class="delete" data-id="<%= posts[i]._id %>">삭제</button>
<% } %>
<script>
$('.delete').click(function(e){
var 글번호 = e.target.dataset._id;
$.ajax({
method : 'DELETE',
url : '/delete',
data : {_id : 글번호}
}).done(function(결과){
})
})
</script>