2014-03-06 3 views
0

나는 새로 게시 된 주석을 나머지 부분에 추가하는 주석 시스템을 보유하고 있습니다. 사용자가 댓글을 클릭하면 '삭제'버튼이 표시됩니다.Ajax 호출이 추가 된 항목에 작동하지 않습니다.

사용자가 삭제 버튼을 클릭하면 확인 대화 상자가 표시되고 확인되면 ajax 호출이 완료되어 주석을 제거합니다.

이것은 Ajax 호출이 첨부 된 항목에서 작동하는 것처럼 보이지만 이미 페이지에있는 주석에 완벽하게 적용됩니다.

$(".commentsholder").on("mouseenter", ".textcomment", function(){ 
    var $this = $(this);  
    $(this).closest('.textcomment').find('.commentActionButton').show(); 
    }); 

그리고 댓글 삭제 아약스 :

$(document).on('submit','.delrepcomment',function(){ 
    var $targetComment = $(this); 

    if (confirm('Do you really want to delete this comment?')) { 
    $.ajax({ 
    type: "POST", 
    url: "process/deletecomment.php", 
    data: $targetComment.serialize(), 
    dataType: "json", 
    success: function(response){ 
    if (response.commentDeleted === true) { 
     $("#"+response.commentID).remove(); 
    } 
    else { 
     $('.delrepcomment').after('<div class="error">Something went wrong!</div>'); 
    } 
    } 
    }); 
    return false; 
    } else { 
     return false; 
    } 
    }); 
}); 

이 모든 내가 이것을 사용 버튼을 표시하려면

<div class='textcomment' id='".$commentID."'> 
     <a class='$rightscommentcolor'>USERNAME:</a>&nbsp; 
     THIS IS THE COMMENT TEXT 
     <div class='commentActionButton'> 
      <form action='process/deletecomment.php' method='post' class='delrepcomment'> 
       <input class='deletecommentsubmit' name='submit-delete' type='$buttontype' value='delete'> 
      </form> 
     </div> 
    </div> 

:

그래서 예를 들어 주석은과 같이 보인다 괜찮습니다. 그러나 추가 된 주석의 삭제 버튼을 클릭하면 확인 대화 상자가 표시되지만 주석은 d가 아닙니다. eleted.

나는 아약스 전화가 일어나지 않는다고 생각하게한다.

물건의 아약스면을 제거하고 PHP 페이지를 사용하여 직접 양식을 유지하면 작동합니다. 심지어 추가 된 주석에,하지만 그냥 아약스가 사용되는 때 작동하지 않습니다.

코멘트가과 같이 추가됩니다 : 당신이 AJAX를 통해 새로운 코멘트를 추가하면

if (response.commentSuccess === true) { 
     $this.closest('.addcomment').prev().append("<div class='textcomment'><a class='"+response.userRights+"'>"+response.username+":</a>&nbsp;"+response.commentToPost+"<div class='commentActionButton'><form action='process/deletecomment.php' method='post' class='delrepcomment'><input class='deletecommentsubmit' name='submit-delete' type='submit' value='delete'></form></div></div>"); 
    } 
+0

당신이 정말 ('response.commentDeleted은 === TRUE '가 true)와 경우'response.commentID' 올바른을 가지고 들어갈 않도록 위치 : ID로를 찾아 제거 할 수 없습니다 값? – kero

+0

브라우저 개발자 도구의 네트워크 탭에서 ajax 요청의 설정 여부를 확인할 수 있습니다. 전송되는 매개 변수는 무엇이며 서버의 응답은 무엇입니까 –

답변

1

, 당신의 textcomment 사업부의 id 속성을 설정하지 않습니다 그래서 당신이 AJAX 호출에서 돌아 오면,

//DIV does not have id! 
...append("<div class='textcomment'><a class='"+r... 
+0

응답에 id가 설정되어 있습니다. – kero

+0

하지만 페이지의 div에는 id가 없으므로'$ ('#'+ response.commentID)'를 실행하면 빈 jQuery 객체가 만들어집니다. 그것에'.remove()'를 호출하는 것은 아무 것도하지 않습니다. –

+0

오스카 파스가 정확합니다. – dcarrith

관련 문제