-
글쓴이글
-
2022년 6월 24일 21:58 #37277
박현수참가자본인이 쓴 글이 아닌경우 에러가 언디파인드 결과값의 딜리트카운트가 0 인걸 이용해서
본인 글이 아닌경우 alert을 이용해서 경고를 띠우고 싶은데 콘솔에는 문구가 나오는데 alert 창은 안뜨네요... 다른 페이지로 랜더 하려해도 안되구요 해결방법이 어떤게 있을까요???
2022년 6월 25일 10:16 #37299
codingapple키 마스터if문 안에서 응답.send() 어쩌구 하면 됩니다
그럼 브라우저에선 어쩌구 메세지가 도착하면 alert 띄워달라고 코드짤 수 있을듯요
2022년 6월 25일 14:42 #37329
박현수참가자저 if 문 안에서 콘솔을 제외한 다른 센드파일 이나 랜더 샌드 다 안먹는데 왜 그런걸까요...? ㅠㅠ 추가로 '브라우저에선 어쩌구 메세지가 도착하면 alert 띄워달라고 코드짤 수 있을듯요 ' 이건 <%%> 이용에서 ejs 에서 코드를 짜는 건가요??
2022년 6월 25일 17:53 #37346
codingapple키 마스터ajax요청이면 응답.render말고 send 이런걸로 결과 보내주면 됩니다
html파일은 ajax요청하고나서 then() 안에서 서버가보낸 메세지같은거 출력할 수 있습니다
2022년 6월 26일 14:30 #37385
박현수참가자app.delete("/delete", function (요청, 응답) {
요청.body._id = parseInt(요청.body._id);
let 삭제할데이터 = { _id: 요청.body._id, 작성자: 요청.user.id };
db.collection("post").deleteOne(삭제할데이터, function (에러, 결과) {
console.log(결과);
console.log(결과.deletedCount);
if (결과.deletedCount == 0) {
응답.status(200).send("오류");
} else {
응답.status(200).send("완료");
}
});
});<script>
$(".delete").click(function (e) {
let 글번호 = e.target.dataset.id;$.ajax({
method: "DELETE",
url: "/delete",
data: { _id: 글번호 },
})
.done(function (결과) {
location.reload();
console.log(결과);
})
.fail(function (xhr, textStatus, errorThrown) {
console.log(xhr, textStatus, errorThrown);
})
});
</script>ajax요청하고나서 then() 안에서 서버가보낸 메세지같은거 출력할 수 있습니다
then()을 어디다 써야하는건지.. then() 안에서 서버가보낸 메세지 출력 이건 어떻게 하는건지... 2일 동안 구글링하고있는데 모르겠습니다...ㅠㅠ
2022년 6월 26일 14:45 #37386
박현수참가자<script>
$(".delete").click(function (e) {
let 글번호 = e.target.dataset.id;$.ajax({
method: "DELETE",
url: "/delete",
data: { _id: 글번호 },
})
.done(function (결과) {
location.reload();
console.log(결과);
})
.fail(function (xhr, textStatus, errorThrown) {
console.log(xhr, textStatus, errorThrown);
})
.then(function (에러, 결과) {
if (에러 === "오류") {
alert("니글 아님!");
}
});
});
</script>이렇게 쓰니까 작동하네요 ㅎㅎ;; 걍 에라 모르겠다하고 써봣더니.;;; ㅋㅋㅋ
2022년 6월 26일 18:15 #37393
codingapple키 마스터then이랑 done이랑 똑같아서 done 안에 적으면 됩니다
location.reload 이건 굳이 필요없을듯요
-
글쓴이글
- 답변은 로그인 후 가능합니다.