새로고침 없는 댓글 삭제를 시도 중입니다.
예전에는 잘 했었는데ㅜㅜ
이번에는 exec_json을 실행시키면 '잘못된 요청입니다'라는 경고문구가 뜨고 스크립트 명령을 튕겨냅니다.
function delComment(comment_srl) { var message = confirm('댓글을 정말로 삭제하시겠습니까?'); if ( message ) { exec_json('board.procBoardDeleteComment', {comment_srl: comment_srl}, function(r) { console.log(r); location.reload(); }); } else { var li = $('#comment_' + comment_srl); toggleCommentForm(li, 'delete'); return false; } }
현재 위와 같이 되어 있는데요.
콘솔로 찍어봐도 r값이 찍히질 않아요.
이 함수를 실행시켜주는 건 아래의 클릭 이벤트인데요.
// Modify and Delete Comment Directly $(document).on('click', '.fdb_nav a[href*="dispBoardModifyComment"], .fdb_nav a[href*="edit"], .fdb_nav a[href*="dispBoardDeleteComment"], .fdb_nav a[href*="delete"]', function() { var li = $(this).closest('li'); var type = $(this).attr('href').indexOf('elete') === -1 ? 'edit' : 'delete'; if ( !li.find('form[rel='+ type +']').length ) { $.get($(this).attr('href')).done(function(response) { var content = $(response).find('form')[0].outerHTML; $(content).attr('rel', type).css({'border-top':'none'}).hide().appendTo(li); toggleCommentForm(li, type); if ( type === 'delete' ) { var target_srl = li.find('[name="comment_srl"]').val(); li.find('form[rel='+ type +']').attr('onsubmit', 'return delComment('+ target_srl +');'); } li.find('form[rel='+ type +']').find('[onclick^="history.back()"]') .attr('onclick', 'toggleCommentForm(jQuery(this).closest(\'li\'), \''+ type +'\'); return false;'); }); } else { toggleCommentForm(li, type); } return false; });
댓글 목록에서 삭제 링크를 클릭하면 -> 해당 페이지를 $.get으로 갖고 와서 -> 삭제 명령일 경우 -> form 부분의 onsubmit 속성을 return delComment('+ target_srl +') 으로 해주고 있습니다.
그렇게 해서 스킨 템플릿 수정 없이 스크립트만으로 댓글 삭제를 하려고 하는 거죠.
문제 해결을 위해 다음과 같은 시도를 해봤습니다.
- 댓글번호에 해당하는 target_srl에 따옴표도 해주고 다해봤는데 결과는 계속 동일해요.
- 혹시 몰라 board 모듈의 module.xml을 봤는데 procBoardDeleteComment가 누락되지 않고 존재하고 있고,
- procBoardDeleteComment 함수에 들어가서 디버그를 찍어봤는데도 오류 메시지가 검출되지 않는 건 exec_json 차원에서 실행이 안된다는 뜻 같은데요.
제가 어느 부분을 놓치고 있는 것일까요?
https://dev.aporia.blog/board_zjsF61/44317
여기에서 댓글 생성하고 직접 삭제 시도를 해보시고 조언 주시면 감사하겠습니다.
AJAX 없이 댓글 삭제 폼을 제출할 때와 exec_json으로 제출할 때 실제로 어떤 데이터가 오고가는지 개발자도구 네트워크 탭에서 찍어보세요. 꼭 필요한 변수가 누락되었을 가능성이 높습니다. 예를 들면 mid라든지... mid가 필요할 수도 있고, mid가 빠졌는지도 모르죠... ㅎㅎ