按钮onclick看起来像这样onclick="return confirm('Are you sure to delete this item?')"
。即使点击取消,帖子仍然被删除。onclick取消按钮仍然呼叫ajax
然后在jquery中。
$(document).ready(function(){
$('.btn').click(function(event){
event.preventDefault();
$a = $(this).text().trim();
if ($a == "Delete")
{
var postid = $(this).next('.postid').val();
$(this).closest(".todo-content").fadeOut('slow');
$.ajax({
type: "POST",
url: BASE_URL+'classes/deletepost',
dataType: 'json',
data: {postid: postid},
async: false,
success: function(data) {
},
error: function(xhr, status, error) {
// check status && error
}
});
}
});
});
如果点击确认中的取消,是否有取消对ajax的调用?
我建议不要使用按钮的文本来确定它的行为。另外,不要使用同步Ajax。 –
是的,我已经修好了。忘了删除这个问题哈哈。我想我仍然必须选择最好的答案 – iamdevlinph