2014-01-15 2 views
0

거의 2 년 전에 php/ajax 코멘트 스크립트를 다운로드했으며이 작은 문제는 첫날부터있었습니다. 나는 저자에게 연락하려고 시도했지만, 그는 어디에서 찾을 수있는 사람이 아닙니다.Ajax POST 시스템과 함께 코멘트 시스템

가끔 "보내기"버튼을 클릭하면 버튼이 비활성화 상태로 유지되고 아무런 변화가 없습니다. 애니메이션으로 바쁜 그림을 계속해서 보여줍니다. 오류 메시지가 전혀 표시되지 않습니다.

당신 중 누구라도이 문제를 도와 줄 수 있는지 궁금합니다.

<div class="comment_heading">Leave a Comment</div> 
<div class="post_comment"> 
<textarea name="txtpostcomment" id="txtpostcomment-'.$postid.'" class="txtpostcomment"></textarea> 
<button class="btnpostcomment" id="btnpostcomment-'.$postid.'" onclick="comment('.$postid.');" type="button">Send</button> 
<input type="hidden" name="token" id="token" value="'.$_SESSION['token'].'"> 
<script>document.getElementById("txtpostcomment-'.$postid.'").focus();</script> 
</div> 

comment = function(postid1) 
{ 
    var txt = $('#txtpostcomment-'+postid1); 
    var btn = $('#btnpostcomment-'+postid1); 

    var comment1 = $(txt).val(); 
    var token = $("#token").val(); 

    $(btn).css('background-image', 'url(/comments/submit-busy.gif)'); 
    $(btn).attr('disabled', true); 

    $.post("/comments/submit.php",{commenting:1, postid:postid1, comment: comment1, name: name, token: token}, 
    function(msg) 
    { 
     if(msg.status) 
     { 
      $('.post_comment .error_msg').remove(); 
      $('.comment-list-'+postid1).prepend(msg.html); 
      $(txt).val(''); 
      $('.comChars').empty(); 
     } 
     else 
     { 
      $('.post_comment .error_msg').remove(); 
      $('.error_msg').clone().appendTo('.post_comment'); 
      $('.error_msg:last').append(msg.error); 
     } 

     $(btn).css('background-image', 'none'); 
     $(btn).attr('disabled', false); 
     $(txt).attr('disabled', false); 

    },'json'); 
} 
+0

$ .ajax에는 더 많은 옵션과 유연성이 있습니다. –

답변

1

당신의 코드는 Ajax 요청이 (인해 네트워크 단절 등 서버 오류) 실패 할 경우에 대비해 오류 상태를 확인하지 않은 것 같습니다 :

다음은 관련 코드입니다. js 오류가 있는지 자바 스크립트 콘솔을 확인하십시오. $.post을 사용하고 있으므로 사용중인 jQuery 버전이 오류 처리를 지원하도록 코드를 확장해야 할 수 있습니다. 또는 $.ajax을 사용하십시오. 자세한 내용은 http://api.jquery.com/jquery.post 또는 http://api.jquery.com/jquery.ajax

관련 문제