본문 바로가기
카테고리 없음

WebSocket을 이용한 실시간 알림 기능

by 그래놀라_ 2021. 8. 17.

후..

 

일단 코드 작성 후 실행해보는데 만난 에러들

 

 1  jquery 넣어줘라..

Uncaught ReferenceError: $ is not defined

jqeury 다운 없이 cnd으로 script추가

 

 2  사실은 쓰면 안 되는 거엿음;;

 

닌 또 뭐냐..

 $.ajax is not a function

https://memostack.tistory.com/181

 

[오류 해결] $.ajax is not a function 해결 방법

Uncaught TypeError: $.ajax is not a function 오류 용량을 줄이려고 slim 빌드 jQuery 를 사용했었는데, slim 빌드를 사용하게되면, $.ajax() 를 사용할 수 없다. 구글에 검색해본 결과, stack overflow 에서 아..

memostack.tistory.com

slim버전 빼야한단다 아래는 수정 코드

<!--
<script src="https://code.jquery.com/jquery-3.6.0.slim.js" 
		integrity="sha256-HwWONEZrpuoh951cQD1ov2HUK5zA5DwJ1DNUXaM6FsY=" 
        crossorigin="anonymous"></script>
-->    		
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>

 

 

 3  데이터 타입 문제 

$.ajax({
    type : 'POST',
    url : '/api/replyComments/auth_yura/2',
    data : {
   		"replyCommentContent": "plz... "
    },
    contentType: "application/json; charset=utf-8",
    dataType : 'json',

    success: function() {
    	socket.send("send!!,"+caller+","+receiver);
    },
    error : function(err){
    	console.log(err);
    }
});

 

400에러가 나서 터미널 가서 봤도니 

Unrecognized token 'replyCommentContent': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

https://dev-yujji.tistory.com/3

 

[Error] ajax 사용 중 'JSON parse error: ~'

ajax로 이것저것 해보던 중 에러를 만났다. JSON parse error: Unrecognized token 'param1': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com..

dev-yujji.tistory.com

 지정해 놓은 url로 넘겨주기 원하는 값들을 data라는 곳에 넣는 구문이다.

이때 ajax는 저 data를 문자열화 해주지 않기 때문에 Controller에서 받아줄 때에 에러가 생긴다. JSON.stringify는 JSON 객체를 String 객체로 변환 시켜주기 때문에 Controller에서 에러 없이 받아주게 된다.

 

$.ajax({
				:
    data : JSON.stringify ({
   		"replyCommentContent": "plz... "
    }),
				:
});

 

 4  살려조

 

 

 

 

https://simsimjae.tistory.com/25

 

[스프링/spring] 웹 소켓을 활용한 쪽지 알람 기능(페이지 이동시)

이 사진 처럼 페이지를 이동할때마다 현재 나에게 도착한 쪽지의 개수를 출력 하는 방법을 알아 보겠습니다. 실시간 채팅, 실시간 알림 기능등에 사용되는 웹 소켓을 사용해서 구현 했습니다.

simsimjae.tistory.com

https://bloodfinger.tistory.com/40

 

Spring 실시간 알림(webSocket)

구현 목록 1)로그인 되어 있는 사람의 글에 누군가 로그인 하고있는 회원이 좋아요 , 팔로우 , 스크랩을 했을때 글의 주인에게 실시간으로 알림이 가는것. 2)만약 로그인이 되어 있지 않다면 그

bloodfinger.tistory.com