The browser stops making ajax requests after 8 requests

0

my case is: I'm doing a login and I want to check if the user already exists in the database, it goes well, until it does it 8 times (the user is an email, so you have to write more than 8 times), then the $ method. post stops working.

$(document).ready(function () {
            $("#email").on("keyup", function () {
                console.log("entro en el keyUp");
                $.post("<c:url value='/RegistroLogin'/>", {
                    datoEmail: $("#email").val()
                }, function (respuesta) {
                    if (respuesta == "true") {
                        console.log("usuario encontrado");
                        $("#enUso").html("<p class='bg-danger'>Usuario en uso</p>");
                    } else {
                        console.log("usuario no encontrado");
                        $("#enUso").html("<p class='bg-success'>Usuario disponible</p>");
                    }
                }).fail(function () {
                    console.log("FALLO");
                });
            });
        });

I am using jsp, servlets and MySQL. I have to say that I BELIEVE that what peta is the browser, since if I run the application with another browser ajax responds perfectly, until the 8th query (again).

It's my first question, if details are missing let me know, thank you very much.

EDIT: add the network tab in chrome and firefox

    
asked by Panbo 23.11.2017 в 11:50
source

1 answer

1

Viewing the screens, it is clear that your problem is in the delay of the server to your requests AJAX .

To avoid this, the best thing you can do is in the Onkeyup event, use some regular expression to check if it is an email. A possible solution would be

$("#email").on("keyup", function () {
console.log("entro en el keyUp");
var MailRegEx=/^[-\w.%+]{1,64}@(?:[A-Z0-9-]{1,63}\.){1,125}[A-Z]{2,63}$/i;
if (MailRegEx.test($("#email").val())){
    console.log("usuario válido"); //Es una dirección de email
    $("#enUso").html("<p class='bg-danger'>Usuario Válido</p>");
}
else{
    console.log("usuario no válid"); //No es una dirección de mail
    $("#enUso").html("<p class='bg-success'>Usuario No válido</p>");
}                
)};

Then once the email address is validated, in the OnBlur event, you could make your call AJAX

$(document).ready(function () {
            $("#email").on("blur", function () {
                console.log("entro en el keyUp");
                $.post("<c:url value='/RegistroLogin'/>", {
                    datoEmail: $("#email").val()
                }, function (respuesta) {
                    if (respuesta == "true") {
                        console.log("usuario encontrado");
                        $("#enUso").html("<p class='bg-danger'>Usuario en uso</p>");
                    } else {
                        console.log("usuario no encontrado");
                        $("#enUso").html("<p class='bg-success'>Usuario disponible</p>");
                    }
                }).fail(function () {
                    console.log("FALLO");
                });
            });
        });

PD Regular Mail Expression is up to date

    
answered by 23.11.2017 / 13:32
source