• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 list에서항목 클릭하면 detail 페이지뜨게하기

list에서항목 클릭하면 detail 페이지뜨게하기

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #10269

    김건우
    참가자

    숙제로 되어있어서 질문드립니다. 

          <h4 class="todotitle" data-id="<%= posts[i]._id %>">할일제목: <%= posts[i].제목 %></h4>

     

     

          $('.todotitle').click(function(e){
              console.log('클릭');
              let 글번호 = e.target.dataset.id;
              $.ajax({
              method:'GET',
              url:'/detail/:'+글번호,
            })
          })

    이런식으로 했는데, 클릭을 해도 console에만 '클릭'이 뜨고 detail 페이지로는 이동이안됩니다.

    server.js에는

    app.get('/detail/:id',function(req,res){
       db.collection('post').findOne({_id : parseInt(req.params.id) },function(err,client){
          res.render('detail.ejs',{ data : client });
       })
    })

    이 입력되어 있는 상태구요 

    어떻게 구현해야하는건가요 ? 

    #10276

    codingapple
    키 마스터

    ajax로 get요청을 보내는게 아니라

    현재 url을 /detail/1로 바꿔주세요~ 라고 코드를 짜면 됩니다

    window.location 어쩌구를 쓰면 되고

    url바꾸는게 실은 get요청이랑 똑같습니다 

    #10281

    김건우
    참가자

            $('.main-title').click((e)=>{
               let todoNumber = e.target.dataset.id;
               window.location.href = 'http://localhost:8080/detail/'+todoNumber;
            })

    이군요 감사합니다. 

    #10302

    codingapple
    키 마스터

    window.location.href = ‘/detail/’+todoNumber;

    상대경로로 만들어놓으면 더 괜찮을듯요 

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠