Make Alert after Hide() of a loading

Asked

Viewed 36 times

0

I’m starting some studies with Jquery, and I’m having a problem.

I am making a login page and I made a loading. This loading only appears later when Submit is made, that is to say...

$('#form-login').submit(function () {
    $('.wait').show();
});

and I use it too

$(document).ready(function () {
    $('.wait').hide();
});

but I send a data per parameter on this page, and get to make an Alert, as follows:

if (mensagem == 1) {
    alert("alerta 1");
} else if (mensagem == 2) {
    alert("alerta 2");
}

but I needed that when this warning was to appear, it would remove this loading that was appearing.

I’ve tried it this way:

if (mensagem == 1) {
    $('.wait').hide();
    alert("alerta 1");
} else if (mensagem == 2) {
    $('.wait').hide();
    alert("alerta 2");
}

and it didn’t work, the loading continues to appear along with the alert.

Note: "message" is the variable that receives the parameter that is passed.

EDIT: I’ll leave my jquery code below.

$(document).ready(function () { //Função que será realizada quando carregar a página
    $('.wait').hide();
    //Pega o valor dos parametros da URL
    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
            }
        }
    };

    var mensagem = getUrlParameter('msg'); //Passa o valor do parâmetro da URL para a variável 'mensagem'

    //Remove o parâmetro da URL
    var uri = window.location.toString();
    if (uri.indexOf("?") > 0) {
        var clean_uri = uri.substring(0, uri.indexOf("?"));
        window.history.replaceState({}, document.title, clean_uri);
    }

    //Faz o alerta de verificação
    if (mensagem == 1) {
        alert("Alerta 1");
    } else if (mensagem == 2) {
        alert("Alerta 2");
    } 

    //Verifica os espaços em branco ou vazios ao clicar no botão "Acessar"
    $("#enter").on("click", function () {
        $("[required]", $(this).closest("form")).filter(function (i, e) {
            return !$(e).val().trim();
        }).val('');

        $("#numeroSerie").val($("#numeroSerie").val().trim());
        $("#user").val($("#user").val().trim());
        $("#pass").val($("#pass").val().trim());
    });

    //Cria a mensagem de carregamento (Loading)
    $('#form-login').submit(function () {
        $('.wait').show();
    });
});
  • "Make Alert after", of what? Pf edits the title of your question

  • is altered Ricardo, thank you

  • 1

    What Submit has to do with if’s?

  • 1

    @Sam, I’m just showing you my code, I showed you Ubmit, because that’s where I put the loading show()

  • 1

    @Ricardopunctual, I apologize, I forgot to book you

  • These if’s are inside Ubmit? I’m sorry but I can’t tell how it works. Where are these if’s? Put the full code as you did, and not in parts.

  • 3

    There is nothing wrong with this code, but as you mentioned a Ubmit, I suspect this error may be being caused due to the asynchronous nature of the requests. Maybe that’s why Sam asked about Ubmit. Only with the code not posted to know what is causing the error, it would be better if you post the entire stream of code.

  • @Sam, I left the jquery code in the question

  • Thanks @user140828, I left the code in the question

  • 2

    Instead of hiding the loading in Javascript, you should put it in your CSS: .wait{ display: none; }

  • My God, I don’t believe it was just that... it worked, thank you very much, but I could detail more of why it worked with css and does not work with this jquery function?

  • Alert crashes the browser, and only releases changes to the page when you close it.

  • I got it, I left the answer to the published question, so other people who have the same question can find it easier. Thanks. @Sam

Show 8 more comments

1 answer

3


Just to leave answered here what was the solution, left by @Sam in the comments, is the following...

Instead of hiding the loading in Javascript, CSS should be used:

.wait{ display: none; }

It worked perfectly, the loading was removed at the right time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.