我的 ajax 请求有点困难。看来 $.post 方法根本不起作用,没有发送请求。 firebug 中也没有显示任何内容。
我可以让它工作:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
alert(member_id);
}
});
但不是这个:
$('.comment-remove').click(function (evt) {
evt.preventDefault();
var sure = confirm('Are you sure your want to remove your comment from this thread?');
if(sure) {
var comment_id = $(this).attr('id');
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.');
}
}
}
});
HTML 是:
<a class="comment-remove" id="<?php echo $comment_id; ?>">Remove my comment</a>
最佳答案
应该是:
$.post('comment.php', { comment_id: comment_id }, function(data) {
if (data === 'success') {
alert(data);
} else {
alert('Unable to remove comment at this time.');
}
})
看到我添加的额外 )
了吗?它与开头处的 $.post(
中的 (
) 相匹配。您错过了它,它总是很容易做到。您的控制台应该能够告诉您这种类型东西。
关于javascript - jQuery AJAX $.post 不适用于 .click() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20204123/