javascript - 当错误时notify.js不显示通知

标签 javascript ajax error-handling notifications

为什么即使响应对象中存在错误消息,我也没有收到任何错误通知?

 $.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");
}

关于javascript - 当错误时notify.js不显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688956/

相关文章:

javascript - 如何创建公钥/私钥加密- Node js

javascript - .replacewith 每 30 秒

javascript - AngularJS 使用 $http.post() 将模型发布到 json 文件

javascript - 如何通过 AJAX 将 ID 发送到另一个文件并在该文件中使用该 ID

javascript - 在通过 Javascript 提交表单之前执行 ajax 检查

php - 无法从数据库检索数据 PHP、AJAX

error-handling - 我应该在生产前端上登录控制台吗

oracle - 调试 Oracle 批量 DML 错误 - 如何确定哪个值导致了错误?

vb.net - 如何在PowerShell中捕获未处理的错误

javascript - 如何隐藏 Highslide Media Viewer 中的控件?