我已经创建了两个警报,在成功的AddStaff上会出现成功警报,如果一个人员无法添加,则应出现警告警报。这就是我所做的:
<div class="alert alert-success" style="display: none" id="AddLateStudentAlert"><div class="alert alert-warnning" style="display: none" id="WarningAlert">
这是我添加员工的ajax
function AddStaff(Staff) {
ajReq.abort();
ajReq = $.ajax({
type: "POST",
url: "Services/Staff.asmx/Staff",
data: "{'Staff':'" + Staff+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$('#SucessAlert').show();
$("#AddLateStudentAlert").fadeOut(5000);
},else:(!sucess) {
$('#WarningAlert').show();
}
警报剂量不起作用,添加人员时,它始终显示警告警报。谁能告诉我为什么?
答案 0 :(得分:0)
使用error
,因为else
不是$.ajax
的有效功能。请参阅jQuery的 AJAX docs 。
示例:
success: function (msg) {
$('#SucessAlert').show();
$("#AddLateStudentAlert").fadeOut(5000);
},
error: function(msg) {
$('#WarningAlert').show();
}
答案 1 :(得分:0)
function AddStaff(Staff) {
ajReq.abort();
ajReq = $.ajax({
type: "POST",
url: "Services/Staff.asmx/Staff",
data: "{'Staff':'" + Staff+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$('#SucessAlert').show();
$("#AddLateStudentAlert").fadeOut(5000);
},
error:function() {
$('#WarningAlert').show();
}
}
}
答案 2 :(得分:0)
jQuery.ajax.中没有else
回调使用错误回调
success: function (msg) {
$('#SucessAlert').show();
$("#AddLateStudentAlert").fadeOut(5000);
},
error:(jqXHR,textStatus,errorThrown ) {
console.log(errorThrown)
$('#WarningAlert').show();
}