Open a modal after a Keypress event?

0

Hello Programmers I am working on an mvc project in an electronic entry to be more specific, I am trying to validate that if an employee is not authorized to enter an area the system generates a modal with the message of UNAUTHORIZED ACCESS attached the code to see what I'm doing wrong:

<div class="modal" id="NoAutorizado" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">No Autorizado</h5>                    
                </div>
                <div class="modal-body">
                    <h1>Acceso no autorizado</h1>
                </div>                
            </div>
        </div>
    </div>

This is the code generated by the modal with bootstrap 4

<script>
$("#txtGafete").keypress(function (e) {

            if(e.keyCode = 13)
            {
                var gafete = $("#txtGafete").val();
                var mm;                
                $.ajax({
                    url: "http://localhost:49851/api/empleadoAutorizado/" + gafete,
                    method: "GET",
                    contentType: "application/json",                    
                    success: function (data) {                        
                        if (data == null) {                           
                            denegado();
                        } else {
                            $("#txtNombre").val(data.nombre);                           
                        }

                    }
                });
            }
        });
</script>

The modality should be executed if the employee does not exist in the database is shown as null, I call it with the function denied in which I have the following code

 function denegado()
        {
            $('#NoAutorizado').show();
            setInterval(function () { $('#NoAutorizado').show('hide'), 3000 })                      
        }

when executing the project the modal is activated when starting to introduce the employee's badge and what I try is to only show if the employee does not exist in my database that may be failing in my code, thank you for your comments

    
asked by Reyes 23.03.2018 в 21:05
source

1 answer

3

how are you?

Change this

if(e.keyCode === 13){

instead of a single "=" add 2 more to ensure that it is the correct variable type, that will work for you.

Greetings!

    
answered by 23.03.2018 / 21:12
source