ajax 댓글 새로고침 클릭 문제 문의드립니다. 채택완료
nsnsksks님 팁으로 그누보드 5.4.2.2에 ajax 댓글 새로고침없이 달기를 적용했는데요. https://sir.kr/g5_plugin/4972
댓글 등록은 잘됩니다.
문제는

즉 새로고침이 안되어서 클릭이 안됩니다. 페이지 전체 새로고침하면 클릭이 잘됩니다.
아래의 코드에서 어떻게 수정하면
고수님들 도움 좀 부탁 드립니다.
view_comment.skin.php 댓글부분<!-- 댓글 시작 { -->
<ajaxcomment>
<section id="bo_vc">
...
</section>
</ajaxcomment>
<!-- } 댓글 끝 -->
view_comment.skin.php fviewcomment_submit 함수 추가
// ajax comment system
$.ajax({
url: f.action,
type: 'POST',
data: $(f).serialize(),
dataType: 'html',
})
.done(function(str) {
var tempDom = $('<output>').append($.parseHTML(str))
var title = $('title', tempDom).text()
if (title === '') {
// 1. commentBox 원위치
comment_box('', 'c')
// 2. commentBox Form 리셋
f.reset()
// 3. 코멘트 출력
$.ajax({
url: str,
type: 'GET',
dataType: 'html'
})
.done(function(str2) {
var tempDom2 = $('<output>').append($.parseHTML(str2))
$('ajaxcomment').replaceWith($('ajaxcomment', tempDom2))
})
}
댓글 옵션창 열기 코드
<script>
$(function() {
// 댓글 옵션창 열기
$(".btn_cm_opt").on("click", function(){
$(this).parent("div").children(".bo_vc_act").show();
});
// 댓글 옵션창 닫기
$(document).mouseup(function (e){
var container = $(".bo_vc_act");
if( container.has(e.target).length === 0)
container.hide();
});
});
</script>
댓글열기 코드
$(function() {
//댓글열기
$(".cmt_btn").click(function(){
$(this).toggleClass("cmt_btn_op");
$("#bo_vc").toggle();
});
});
</script>
<?php } ?>
답변 1개
$(".btn_cm_opt").on("click", function(){
->
$(document).on("click", ".btn_cm_opt", function(){
$(".cmt_btn").click(function(){
->
$(document).on("click", ".cmt_btn", function(){
이런식으로 수정해보세요
동적 생성된 element들은 jquery 버전에 따라
bind, on, live 쓰는 방식들이 조금씩 다릅니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
알려주신대로 하니 잘되네요~
코로나 조심하시고 건강하세요~^^