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

home2 게시판 Node.js, Express 게시판 jquery 통신오류

jquery 통신오류

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

    김민주
    참가자
    아작스로 chatroom으로 서버를 요청하면 콘솔창에 
    POST http://localhost:8080/chatroom 500 (Internal Server Error) jquery-3.4.1.js:9837 
    send( options.hasContent && options.data || null );가 에러가 뜹니다.
    
    이유가 무엇일까요?
    
    server.js 
    app.post('/chatroom',로그인했니,(req,res)=>{
        var save = {
            title : req.body.당한사람,
            member : [ObjectId(req.body.당한사람id), req.user._id],
            date : new Date()
          }
        
          db.collection('chatroom').insertOne(save).then((result)=>{
              res.send('저장완료')
          });
    })
    
    (jquery)
    
    $('#chat').click(function(e){
            var id = e.target.dataset.id;
            
            $.post('/chatroom', {당한사람id : id}).then(()=>{
                
            })
            });
        
    
    
    
    
    
    #70224

    codingapple
    키 마스터
    ajax요청하기 전에 당한사람id 라는 변수가 잘 있나 출력해봅시다
    #70343

    김민주
    참가자
    
    
    
    콘솔로 찍으면 잘 나옵니다 하지만 에러를 보면 이렇게 나옵니다ㅠㅠ
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Error</title>
    </head>
    <body>
    
    BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer<br> &nbsp; &nbsp;at new BSONTypeError (C:\Users\com_01\Desktop\butterfly\poca\node_modules\bson\lib\error.js:41:28)<br> &nbsp; &nbsp;at new ObjectId (C:\Users\com_01\Desktop\butterfly\poca\node_modules\bson\lib\objectid.js:67:23)<br> &nbsp; &nbsp;at ObjectId (C:\Users\com_01\Desktop\butterfly\poca\node_modules\bson\lib\objectid.js:26:20)<br> &nbsp; &nbsp;at C:\Users\com_01\Desktop\butterfly\poca\server.js:434:19<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (C:\Users\com_01\Desktop\butterfly\poca\node_modules\express\lib\router\layer.js:95:5)<br> &nbsp; &nbsp;at next (C:\Users\com_01\Desktop\butterfly\poca\node_modules\express\lib\router\route.js:144:13)<br> &nbsp; &nbsp;at 로그인했니 (C:\Users\com_01\Desktop\butterfly\poca\server.js:139:1)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (C:\Users\com_01\Desktop\butterfly\poca\node_modules\express\lib\router\layer.js:95:5)<br> &nbsp; &nbsp;at next (C:\Users\com_01\Desktop\butterfly\poca\node_modules\express\lib\router\route.js:144:13)<br> &nbsp; &nbsp;at Route.dispatch (C:\Users\com_01\Desktop\butterfly\poca\node_modules\express\lib\router\route.js:114:3)

    </body>
    </html>

    #70344

    김민주
    참가자
    에러를 보니 BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
        at new BSONTypeError 이렇게 나옵니다!
    
    #70351

    codingapple
    키 마스터
    다루고있는 ObjectId같은거 출력해서 뒤에 이상한 공백은 없나 확인해봅시다
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 호 / 개인정보관리자 : 박종흠