2014-01-15 73 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請求失敗(由於網絡連接斷開,服務器錯誤等)。檢查您的JavaScript控制檯是否有任何js錯誤。由於它使用的是$.post如果您正在使用的jQuery版本支持它,您可能需要擴展代碼以添加錯誤處理。或者,也可以使用$.ajax。欲瞭解更多信息,請登錄http://api.jquery.com/jquery.posthttp://api.jquery.com/jquery.ajax