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

home2 게시판 Node.js, Express 게시판 로그인을 해야만하고 그 로그인 사용자가 글쓴걸 수정할때

로그인을 해야만하고 그 로그인 사용자가 글쓴걸 수정할때

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

    이해욱
    참가자
    server.js
    
    app.put('/edit', function(요청, 응답){
      var id= parseInt(요청.body.id);
      var title=요청.body.title;
      console.log(title);
      var content=요청.body.content;
      var user_id=요청.user[0].user_id;
      var sql= 'UPDATE post INNER JOIN login ON login.id=post.numberid SET title=?, content=? WHERE login.user_id=? AND post.id=?';
      connection.query(sql,[title,content,user_id,id], function(err,result){
        if(err)
        {
          console.log(err)
          응답.status(500).send('Internal Server Error');
        }
        else
        {
          응답.render('/list',{posts : result});
        }
      });
    });
    
    edit.ejs
    <form action="/edit?_method=PUT" method="POST">
                    <input value="<%= posts.id %>" name="id" style="display : none;">
                    <label>제목</label>
                    <input value="<%= posts.title %>" type="text" class="form-control" name="title" style="width: 770px;">
                    <label>내용</label>
                    <input value="<%= posts.content %>" type="text" class="form-control wow" name="content" style="width: 770px;">
                    <button type="submit" class="btn btn-primary">Pri
    
    
    수정 버튼은 detail.ejs 에 넣었는데요
    <div class="title2">
          <%= posts.title %>
    </div>
    <div class="bt_wrap">
                        <button class="edit on" data-id="<%= posts.id %>">수정</button>
     </div>
     <script>
     $('.edit').click(function(e){
            var 글번호=e.target.dataset.id;
            var 지금누른거 = $(this);
            $.ajax({
                method:'PUT',
                url:'/edit',
                data: {id: 글번호}
            }).done(function(결과){
                window.location.href ='/list';
            }).fail(function(a,b,c){
                console.log(a,b,c,);
            });
        })
     </script>
     title을 을줬는
    var title=요청.body.title;
    console.log(title); 
    값 undefined 이 뜹니다
    왜그러는지 도대체 이해가안됩니다
    
    
    #62422

    codingapple
    키 마스터
    이해말고 버튼누르면 title이라는 이름으로 데이터 전송 잘 하고 있는지 출력이나 확인부터 해보면 됩니다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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