2010-12-20 44 views
0

我已经创建了脚本,每次用户添加新评论或删除评论时都会加载评论部分。JQuery每次点击时都会复制我的评论

的删除完美的作品,但是当我添加注释的脚本添加1条评论我第一次点击提交,2条评论接下来的时间,5在下,10就下,ECT ....

我无法弄清楚它为什么重复这样的评论。

这里是我的代码:

function refreshComments(r_id) { 
    var ar = $("#arr" + r_id).attr("class"); 
    $("#cali" + r_id).load("../functions/inC.php",{"id" : r_id,"ar" : ar},function() {   


    var link = $("#dani #delete" + r_id); 
    $(link).click(function() { 
    c_id = $(this).attr("class"); 

    $(".loading" + r_id).load("../functions/delete.php",{"id" : c_id}); 
    refreshComments(r_id); 
    return false; 
    }); 

$("#internal" + r_id).button(); 
$("#internal" + r_id).click(function() { 
$(".loading" + r_id).html('<img src="../img/ajax-loader.gif" style="width:100px; margin-top: 10px;" />'); 
     var comment = ""; 
     var comment = $("#comment" + r_id).val(); 
     var status = "public"; 
     alert(comment); 

    $(".loading" + r_id).load("../functions/addMessage.php",{"id" : r_id,"comment" : comment, "status" : status}); 
    refreshComments(r_id); 
     return false; 
      }); 

    return false; 

    }); 


} 

理想情况下,我想只是追加到列表顶部的实际发表评论,但我不太清楚如何做到这一点。

感谢您的帮助。

回答

0

感谢您发布示例代码。但是,我不能完全确定问题,因为我不知道你的后端是干什么的。

从您的问题描述中,可能的原因可能是您不只是加载评论,还会保留以前加载的评论。这看起来像重复。

您有0评论。您看到0条评论。提交评论,全部下载并添加1.

您有1评论。你看到1条评论。提交评论,全部下载并添加2.

您有2评论。你看到3条评论。提交评论,全部下载并添加3.

您有3评论。你看到6条评论。提交评论,全部下载并添加4.

您有4评论。你看到10条评论。 etc

这看起来像你的问题?

相关问题