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

home2 게시판 Node.js, Express 게시판 mysql로 node.js 연동할때 요청.query.value값을 못 가져옵니다.

mysql로 node.js 연동할때 요청.query.value값을 못 가져옵니다.

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

    이해욱
    참가자
    server.js
    app.get('/search',function(요청, 응답){
      console.log(요청.query.value);
      var title = 요청.query.value;
      var sql = 'SELECT title FROM post WHERE title=?';
      connection.query(sql,[title],function(err,topcis){
        console.log(topcis)
        if(err)
        {
          console.log(err);
          응답.status(500).send('Internal Server Error');
        }
        else
        {
          응답.render('search.ejs',{posts : topcis});
        }
      })
    })
    list.ejs
    
    <body>
        
        <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
        <div class="_container">
            <div class="header">
                <%- include('nav.html')%>
            </div>
            <div class="left-menu"></div>
            <div class="center-menu">
                <h4>글</h4>
                <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>
                <ul class="list-group">
                    <% for(var i=0; i < posts.length; i++) { %>
                        <li class="list-group-item">
                            <h4>글 번호: <%= posts[i].id %></h4>
                            <p>제목 : <%= posts[i].title %></p>
                            <button class="btn btn-danger delete" data-id="<%= posts[i].id %>">삭제</button>
                       

                    <% } %>            

            </div>         <div class="right-menu"></div>         <div class="footer"></div>             </div>     <script>     $('#search').click(function(){         var 입력한값 = $('#search-input').val();         window.location.replace('/search?value='+입력한값);     })

    에러는 안뜨는데 검색 값undefined 뜹니
    
    
    콘솔창 
    undefined
    []
    
    #60812

    codingapple
    키 마스터
    <input>에 id="search-input"이 없는듯요
    #60861

    이해욱
    참가자
    list.ejs
    <body>
        
        <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
        <div class="_container">
            <div class="header">
                <%- include('nav.html')%>
            </div>
            <div class="left-menu"></div>
            <div class="center-menu">
                <h4>글</h4>
                <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>
                <ul class="list-group">
                    <% for(var i=0; i < posts.length; i++) { %>
                        <li class="list-group-item">
                            <h4>글 번호: <%= posts[i].id %></h4>
                            <p>제목 : <%= posts[i].title %></p>
                            <button class="btn btn-danger delete" data-id="<%= posts[i].id %>">삭제</button>
                    <% } %>            
            </div>         
    <div class="right-menu"></div>       
      <div class="footer"></div>             
    </div>   
      <script>     
    $('#search').click(function(){
             var 입력한값 = $('#search-input').val();   
          window.location.replace('/search?value='+입력한값);
         })
    </script>
    
    에러는 안뜨는데 검색 값undefined 뜹니다
    
    <input class="form-control" id="'search-input"> 있습니다
    
    #60903

    codingapple
    키 마스터
    search-input 왼쪽에 이상한 따옴표가 있는듯요
    #60998

    이해욱
    참가자
    감사합니다
5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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