-
글쓴이글
-
2021년 8월 20일 01:04 #13767
김창모참가자<div class="container input-group mb-2">
<input class="form-control" id="search-input">
<button class="input-group-append btn btn-danger" id="search">검색</button>
</div><script>
$('#search').click(function(){
var 입력한값 = $('#search-input').val()
window.location.replace('/search?value=' + 입력한값)
})
</script>list.ejs에서 해당코드 작성후 검색버튼을 누르면
TypeError: /Users/cmong/Desktop/coding/TodoApp1/views/detail.ejs:30
28| <div class="card" style="width: 100%">
29| <div class="card-body">
>> 30| <h5 class="card-title">제목: <%= data.제목 %></h5>
31| <h6 class="card-subtitle mb-2 text-muted">날짜: <%= data.날짜 %></h6>
32| <p class="card-text">
33| Some quick example text to build on the card title and make up theCannot read property '제목' of undefined
at eval (eval at compile (/Users/cmong/Desktop/coding/TodoApp1/node_modules/ejs/lib/ejs.js:662:12), <anonymous>:15:31)
at detail (/Users/cmong/Desktop/coding/TodoApp1/node_modules/ejs/lib/ejs.js:692:17)
at tryHandleCache (/Users/cmong/Desktop/coding/TodoApp1/node_modules/ejs/lib/ejs.js:272:36)
at View.exports.renderFile [as engine] (/Users/cmong/Desktop/coding/TodoApp1/node_modules/ejs/lib/ejs.js:489:10)
at View.render (/Users/cmong/Desktop/coding/TodoApp1/node_modules/express/lib/view.js:135:8)
at tryRender (/Users/cmong/Desktop/coding/TodoApp1/node_modules/express/lib/application.js:640:10)
at Function.render (/Users/cmong/Desktop/coding/TodoApp1/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/Users/cmong/Desktop/coding/TodoApp1/node_modules/express/lib/response.js:1012:7)
at /Users/cmong/Desktop/coding/TodoApp1/server.js:74:10
at /Users/cmong/Desktop/coding/TodoApp1/node_modules/mongodb/lib/utils.js:530:9이런 에러가 발생합니다
detail.ejs 해당부분 코드
<div class="container mt-4">
<h4 class="text-center">상세 페이지</h4><div class="card" style="width: 100%">
<div class="card-body">
<h5 class="card-title">제목: <%= data.제목 %></h5>
<h6 class="card-subtitle mb-2 text-muted">날짜: <%= data.날짜 %></h6>
<p class="card-text">
Some quick example text to build on the card title and make up the
bulk of the card's content.
</p>
<a href="/edit/data._id" class="card-link">수정하기</a>
</div>
</div>
</div>server.js /detail get요청코드
app.get("/detail/:id", function (요청, 응답) {
db.collection("post").findOne(
{ _id: parseInt(요청.params.id) },
function (에러, 결과) {
console.log(결과);
응답.render("detail.ejs", { data: 결과 });
}
);
});list.ejs 에 검색기능을 추가한후 검색버튼을 누르면 detail 페이지로 이동하는것도 아닌데
왜 갑자기 detail.ejs 에서 에러가 발생하는걸까요 ? ?
2021년 8월 23일 11:27 #13888
김창모참가자server.js
app.get("/search", (요청, 응답) => {
db.collection("post")
.find({ 제목: 요청.query.value })
.toArray((에러, 결과) => {
console.log(결과);
});
});이렇게 되어있습니다
2021년 8월 23일 14:12 #13893
codingapple키 마스터/search로 접속하면 db에서 게시물을 찾아온 후에 아무것도 안하고 있군요
일단 응답.render() 아니면 응답.send() 이런 걸 써서 응답을 해보도록합시다
2021년 8월 24일 12:50 #13957
김창모참가자db에서 게시물을 찾아온 후에 server.js 터미널에서
console.log(결과) 를 실행시켰을때 해당 결과가 출력이 되지 않습니다 ㅠㅠ
-
글쓴이글
- 답변은 로그인 후 가능합니다.