Javascript 删除评论而不刷新页面

Javascript 删除评论而不刷新页面,javascript,php,ajax,Javascript,Php,Ajax,想知道如何改进此代码,以便在删除注释时不刷新页面。如果你在页面的一半删除了一条评论,它又回到了页面的顶部,这会让人很恼火 阿贾克斯 函数删除(pid){ $.ajax({ 类型:“POST”, url:“../include/post.delete.php”, 数据:“pid=”+pid, 成功:函数(){ } }); } 删除邮件 回声'; 如果($streamitem_data['streamitem_type_id']==1 | |$streamitem_data['streamitem_

想知道如何改进此代码,以便在删除注释时不刷新页面。如果你在页面的一半删除了一条评论,它又回到了页面的顶部,这会让人很恼火

阿贾克斯

函数删除(pid){
$.ajax({
类型:“POST”,
url:“../include/post.delete.php”,
数据:“pid=”+pid,
成功:函数(){
}
});
}
删除邮件
回声';
如果($streamitem_data['streamitem_type_id']==1 | |$streamitem_data['streamitem_type_id']==3){
回声“;
}否则{
回声“;
}
$poster_name=_user_core::getuser($streamitem_data['streamitem_creator']);
$target\u name=\u user\u core::getuser($streamitem\u data['streamitem\u target']);
如果($streamitem_data['streamitem_type_id']==1 | |$streamitem_data['streamitem_type_id']==3){
if(!($streamitem_data['streamitem_type_id']==1)){
回声“;
回声“;
}
如果(!($streamitem_data['streamitem_type_id']==3)){
回声“;
}
$cont=stripslashes($streamitem_data['streamitem_content']);
if(!($streamitem_data['streamitem_type_id']==1)){
//$cont=htmlentities($cont);
$cont=ereg_replace(“[:alpha:]+://[^[:space:]+[:alnum://]”,“”,$cont);
}
如果($streamitem_data['streamitem_creator']=$streamitem_data['streamitem_target'])){
回声“说”;
}否则{
回声“
写在
流”;
}
回声“

”; 如果($streamitem_数据['streamitem_类型_id']==1){ $cont=nl2br($cont); 回显“$cont.”; }否则{ 如果($streamitem_data['streamitem_creator']=$streamitem_data['streamitem_target'])){ $cont=nl2br($cont); 回显“$cont.”; }否则{ $cont=nl2br($cont); 回显“'”$cont.”; } } 回声“; if($streamitem_data['streamitem_creator']=$\u SESSION['id'])){ 回声“X”;

}

您需要对刚刚删除的comment元素调用
.remove()
。您需要找出如何识别它。有一种方法:

function delete_(pid){
    $.ajax({
       type: "POST",
       url: "../include/post.delete.php",
       data: "pid="+pid,
       success: function(){
           // However you can identify the comment's div, and delete it by calling .remove()
           // This is if it has a unique id
           $("#comment-"+pid).remove();
       }
     });
}
否则,如果您使用
,您可以添加一个参数,如
。这样您可以通过
$(您传递给函数的\u元素)访问元素。例如,parents(“div.the-comment-div-parent”).remove()


否则,您可以在
$(“a”)中实现此函数。单击(函数{})
如果您正在使用此方法。这取决于您。

让成功处理程序删除注释的dom节点?我将如何执行此操作,请Marc?注释元素是保存注释的div吗?我已经更新了我的代码,因为我不确定我需要调用什么。如果有人可以帮助,请/Yes,d应该删除包含您希望隐藏的所有内容的iv。如果您可以发布一个示例HTML输出,那么您的页面生成的结果将很好,这样我们就可以知道您的HTML结构是什么。您发布的代码产生的内容确实不清楚。我相信您应该使用class
userinfo
删除div(与
div.userinfo
匹配),但名称似乎不相关,因此我不确定。
function delete_(pid){
    $.ajax({
       type: "POST",
       url: "../include/post.delete.php",
       data: "pid="+pid,
       success: function(){
           // However you can identify the comment's div, and delete it by calling .remove()
           // This is if it has a unique id
           $("#comment-"+pid).remove();
       }
     });
}