警报框不会显示,但标签文本会显示

时间:2019-10-10 09:55:36

标签: javascript jquery html

我尝试为登录的用户添加警报消息。当数据正确时,将显示成功登录,并且错误的名称或密码不正确

function mesajConectare(response) {
    if (response.statusLogged == "Succes login") {
        var da = `<div class="alert alert-success alert-dismissible fade show">
        <strong>Success!</strong> Your message has been sent successfully.
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>`
    } else {
        var da = `<div class="alert alert-success alert-dismissible fade show">
        <strong>Success!</strong> Your message has been sent successfully.
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>`
    }
    jQuery('.msgConectare').text(da);

}

javascript:

 success: function (response) {
        var msg = "";
        if (response.statusLogged == "Succes login") {
            window.location = "/pages/admin/index.html";
            window.localStorage.setItem('firstName', response.firstName);
            window.localStorage.setItem('lastName', response.lastName);

            window.localStorage.setItem('userId', response.userId);
            window.localStorage.setItem('email', response.email);
            window.localStorage.setItem('UserName', response.userName);
            window.localStorage.setItem('password', response.password);
            mesajConectare(response);

        } else {
            msg = "Invalid username and password!";
            console.log(msg);
            mesajConectare(response);
        }

    }

HTML

<body class="hold-transition login-page bs-example">
<div class="login-box">
    <div class="login-logo">
        <a href=""><b>Licenta</b>2019</a>
    </div>
    <!-- /.login-logo -->
    <div class="card">
        <div class="card-body login-card-body">
            <p class="login-box-msg">Autentificate in contul personal</p>

            <div class="input-group mb-3">
                <input id="UserName" type="email" class="form-control" placeholder="Email">
                <div class="input-group-append">
                    <div class="input-group-text">
                        <span class="fas fa-envelope"></span>
                    </div>
                </div>
            </div>
            <div class="input-group mb-3">
                <input id="password" type="password" class="form-control" placeholder="Password">
                <div class="input-group-append">
                    <div class="input-group-text">
                        <span class="fas fa-lock"></span>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-8">
                    <div class="icheck-primary">
                        <input type="checkbox" id="remember">
                        <label for="remember">
                            Memoreaza datele
                        </label>
                    </div>
                </div>
                <!-- /.col -->
                <div class="col-4">
                    <button id="login" type="submit" class="btn btn-primary btn-block btn-flat">Conectare</button>
                </div>
                <!-- /.col -->
            </div>

            <div class="social-auth-links text-center mb-3">
                <div class="msgConectare">

                </div>

            </div>

            <!-- /.social-auth-links -->

            <p class="mb-1">
                <a href="#">Mi-am uitat parola</a>
            </p>
            <p class="mb-0">
                <a href="register.html" class="text-center">Utilizator nou</a>
            </p>
        </div>
    </div>
        <!-- /.login-card-body -->
    </div>



<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script src="/js/functii.js">
    jQuery.noConflict();
</script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.js"></script>

mesajConectare

 function mesajConectare(response) {
    if (response.statusLogged == "Succes login") {
        var da = `<div class="alert alert-success alert-dismissible fade show">
        <strong>Success!</strong> Your message has been sent successfully.
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>`
    } else {
        var da = `<div class="alert alert-success alert-dismissible fade show">
        <strong>Success!</strong> Your message has been sent successfully.
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>`
    }
    jQuery('.msgConectare').text(da);
    }

1 个答案:

答案 0 :(得分:0)

使用jQuery('.msgConectare').html(da);代替jQuery('.msgConectare').text(da);