即使在响应对象中存在错误消息,我为什么不收到任何错误通知?
$.ajax(settings).done(function (response) {
if ( "error_message" in response ) {
console.log(response);
$.notify("Rendez-vous existant", "error");
}
else {
$.notify("Rendez-vous ajouté", {"status":"success"});
}
$('.modal.in').modal('hide')
table.destroy();
$('#datatable4 tbody').empty(); // empty in case the columns change
getAppointment()
});
这就是我在控制台日志中得到的:
error_message"Rendez-vous existant, veuillez choisir une autre date"
"error_message" in response
不是正确的javascript语法。假设error_message
属性要么在响应中不存在,要么是某些值其他0, null, false, undefined
,则response.error_message
将被评估为true
。
更改您的条件以阅读:
if (response.error_message) {
console.log(response);
$.notify("Rendez-vous existant", "error");
}