CMS솔루션마켓, 이온디 - 워드프레스, 라이믹스, 카페24, 그누보드, 엑셀

Contents Management System

XE 새로고침 없이 댓글 달기

https://eond.com/xe/391271


2017년도에 새로고침 없이 댓글 달기라는 글을 링크만 적어올린 적이 있었네요. (#반성)

댓글 추천하는 방법에 대해서도 찾아봤지만, 쉽게 적용할 수 있는 팁이 없었습니다.

그리고 서버의 부하 없이 단순히 진짜 정말 새로고침 없는 방법을 생각해봤는데요,


1. 코어에서 일단 새로고침 안하게 수정하기

/modules/comment/comment.controller.php

$output = new BaseObject(-1, $success_message); // 0 이 원래 값 -1로 할 경우 새로고침되지는 않음.

이 값을 0을 -1로 수정합니다.


2. 스킨에서 수정하기

<a class="bd_login" href="#" onclick="doCallModuleAction('comment','procCommentVoteUp','{$comment->comment_srl}');reloadComment('{$comment->comment_srl}','{$comment->get('voted_count')}');return false"|cond="$is_logged" title="{$lang->cmd_vote}"><em><i class="fa fa-heart color"></i> <span class="voteCnt">{$comment->get('voted_count')?$comment->get('voted_count'):0}</span></em></a>

1) reloadComment(코멘트srl,현재코멘트수) 함수를 추가하고, 

2) 댓글 수를 표시한 부분에 태그를 추가해서 쉽게 찾을 수 있도록 클래스를 추가해줍니다. (voteCnt 클래스를 임의로 추가함)


3. 스킨에 스크립트를 추가

/modules/board/skins/sketchbook5_eond/js/board.js

function reloadComment(comment_srl,voteCnt){
   var id = comment_srl;
   var cnt = Number(voteCnt);
   // console.log(id+'코멘트 추천을 눌렀습니다.');
   // console.log(cnt+'코멘트 수.');
   $("#comment_"+id).find(".voteCnt").text(cnt+1);
}

board.js에 reloadComment 함수를 추가해줍니다.

이 방법은 ajax는 아니고 단순히 제이쿼리로 숫자 부분만 텍스트를 변경해주는 방법입니다.

서버의 부하 없이 단순히 브라우저상에서 해당 텍스트의 숫자만 +1 해주는 방법입니다. ^^;


어차피 한번 클릭한 경우는 더 이상 추천할 수 없습니다. 라는 메세지가 뜨고,

새로 접속한 경우는 이미 클릭했던 수가 집계되서 보여지기 때문에 

기존의 다른 팁들보다 서버의 부하 없이 단순하게 구현 가능한 방법이라고 생각되네요.


참조

1) 선택자에 변수 넣기

https://github.com/sooojungee/TIL/blob/master/jQuery/180627.%5BjQuery%5D%20선택자에%20변수%20넣기.md 

2) 수 더하기


https://spoon718.tistory.com/189


참고

https://pilgoo.tistory.com/140

https://www.xpressengine.com/qna/21529873

https://pilgoo.tistory.com/140

https://pilgoo.tistory.com/138

https://www.xpressengine.com/tip/22546396

https://xetown.com/point_contents/1168446

https://xetown.com/tips/130833

https://boxfoxs.tistory.com/293


 
댓글은 로그인 사용자만 작성 가능합니다. 로그인하기