我试图在我的网站上建立一个删除评论链接,类似于通过Twitter设置评论的链接。这样的话,用户不必离开页面,就可以让保留该评论的div消失。我知道我必须通过AJAX进行此操作,但我仍在学习中。到目前为止,这是我设置的内容,但是每次单击链接时,都不会发生任何变化。
$(document).ready(function() {
$('.delete_post').click(function () {
var id = $(this).attr('id');
var data = 'id=' + id.val() + '&submit=yes';
alert(id);
//start the ajax
$.ajax({
url: "<?php echo $url; ?>/process_form/delete_post.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
if (html==1) {
document.getElementById(id).style.display = 'none';
}
else {
alert("Post was not deleted");
}
}
});
return false;
});
});
<a href="#" class="delete_post" id="dp<?php echo $comment["id"]; ?>">Delete</a>
你们可以提供一些建议吗? 非常感谢。