如果我正确理解你的问题,你是在问如何处理ajax请求中的错误条件。 Ajax设置有一个error属性,可以这样使用
$.ajax({
.... other settings you already have
error: function (xhr, ajaxOptions, thrownError) {
swal("Error deleting!", "Please try again", "error");
}
});
另外,您以错误的方式调用 swal 。 Swal 有一个像这样的回调
swal({settings}, function(isConfirm){});
整体代码看起来像这样
function confirmDelete() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function (isConfirm) {
if (!isConfirm) return;
$.ajax({
url: "scriptDelete.php",
type: "POST",
data: {
id: 5
},
dataType: "html",
success: function () {
swal("Done!", "It was succesfully deleted!", "success");
},
error: function (xhr, ajaxOptions, thrownError) {
swal("Error deleting!", "Please try again", "error");
}
});
});
}
这是一个演示http://jsfiddle.net/dhirajbodicherla/xe096w10/33/ http://jsfiddle.net/dhirajbodicherla/xe096w10/33/