app.delete('/delete',function(요청,응답){
요청.body._id = parseInt(요청.body._id);
console.log(요청.body);
db.collection('post').deleteOne(요청.body,function(에러,결과){
if(에러){return console.log(에러)}
app.get('/list',function(요청,응답){
db.collection('post').find().toArray(function(에러,결과){
//포스트에 있는거 모든거 다가져와주세요 array로
응답.render('list.ejs',{ posts : 결과 });
});
});
응답.render('list.ejs',{ posts : 결과 });
})
})
delete.html 거기 자바스크립트 지우기 단추버튼
$('.del').on('click',function(e){
var target = e.target.dataset.id;
$.ajax({
method : 'DELETE',
url : '/delete',
data : { _id : target }
}).done(function(){
location.replace('http://localhost:8080/list');
})
})
선생님은 e.target 으로 부모셀렉터 찾고 리스트 에서 뿅하고 지우는거 했는데요.
저는 그냥 location.reload , 나 replace 로 했는데요 그렇게 하면 잘 안되서 ㅠㅠ 그냥 자꾸 ejs파일 저기서
정의되지 않았다고 에러 떠서
app.get('/list',function(요청,응답){
db.collection('post').find().toArray(function(에러,결과){
//포스트에 있는거 모든거 다가져와주세요 array로
응답.render('list.ejs',{ posts : 결과 });
});
기존에 리스트에 get요청 하라고 만든거 저기 안에다가 넣으니깐 잘 되긴하거든요..
근데 저렇게 말고요.
응답.redirect('/list'); 요렇게 붙여도 될꺼 같에서 붙였는데 안되네요 ..
app.delete('/delete',function(요청,응답){
요청.body._id = parseInt(요청.body._id);
console.log(요청.body);
db.collection('post').deleteOne(요청.body,function(에러,결과){
if(에러){return console.log(에러)}
});
});
응답.redirect('/list');
})
})
이렇게 붙이면 왜 리스트 안보여주고 에러가 날까요? 저는 될 것 같은데 안되네요 ㅠ
수정요청,post요청해서 일기만드는거는 끝에다가 응답.redirect('/list'); 붙이면 잘 되는데
delete 만 안되는 이유가 궁금합니다 ㅠ