| 제목 | 9.2 댓글 삭제 Ajax로 구현하기 - jQuery로 구현 부분 문제 수정 | ||
|---|---|---|---|
| 글쓴이 | 널곰 | 작성시각 | 2015/05/17 02:36:34 | 
|  | |||
| '댓글 삭제 Ajax로 구현하기'  288 페이지 jQuery 코드에서 .comment_delete를 클릭시 이벤트 처리 코드를 구현 했을 경우 댓글 작성후 동적으로 생성된 댓글에 관한 DOM에서의 .comment_delete 버튼이 동작하지 않습니다. 그래서 아래와 같이 수정하였습니다. 
// $(".comment_delete").click(function() {    => 이부분을 아래처럼 변경
$("#comment_area").on('click',".comment_delete", function(e){
            e.preventDefault(); // url에 #생기는 것을 방지.
            $.ajax({
                url: "/bbs/ajax_board/ajax_comment_delete",
                type: "POST",
                data: {
                    "csrf_test_name" : getCookie('csrf_cookie_name'),
                    "table" : "<?php echo $this->uri->segment(3); ?>",
                    "board_id" : $(this).attr("data-vals")
                },
                dataType: "html",
                complete: function(xhr, textStatus) {
                    if (textStatus == 'success') {
                        if (xhr.responseText == 9000) {
                            alert("로그인하여야 합니다.");
                        }
                        else if (xhr.responseText == 8000) {
                            alert("본인의 댓글만 삭제할 수 있습니다.");
                        }
                        else if (xhr.responseText == 2000) {
                            alert("다시 삭제하세요.");
                        }
                        else {
                            $("#row_num_" + xhr.responseText).remove();
                            alert("댓글이 삭제되었습니다.");
                        }
                    }
                }
            });
        }); | |||
| 다음글 | ajax 댓글 등록에서.. responseText: ... (2) | ||
| 이전글 | board 컨트롤러에 있는 lists() 에 포함된 코... (1) | ||
| 
                                변종원(웅파)
                                /
                                2015/05/18 11:46:01 /
                                추천
                                0
                             | 
음.. 2쇄에선 작업을 해서 변경한 기억이 나는데 확실한건 집에 있는 2쇄를 확인해봐야겠네요.
이곳 게시판에 전에 질문을 하셔서 댓글을 달았었습니다. ^^