Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Jquery Not executing correctly when window.location.href is called

I have a function that will post a value to a php page and then run some sql. after it is done I am trying to set the window location.

It works perfectly if I don not have window.location.href, however when I add this line of code It changes the page but does not do the rest.

            $(document).ready(function ()
        {
            $('.delete').click(function ()
            {
                $('.confirm').toggleClass('confirmShow');

                var clickBtnValue = $(this).val();
                var ajaxurl = 'ajaxDelete.php',
                        data = {'action': clickBtnValue};
                $.post(ajaxurl, data, function (response) {

                });
                if ($(this).val() == "Delete Account")
                {
                    $(this).val("yes");
                }
                else if ($(this).val() == "yes")
                {
                    $(this).val("Delete Account");

                    //When the below line is removed it works perfectly
                    window.location.href = 'Functions/LogOut.php';
                }
                else if ($(this).val() == "No")
                {
                    $('#delete').val("Delete Account");
                }               
            });

        });
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As soon as you click the button, you redirect to the Logout page. The ajax call doesn't have time to execute. Put the redirect in the callback (which is currently empty)

$('.delete').click(function () {
    $('.confirm').toggleClass('confirmShow');

    var clickBtnValue = $(this).val();
    var ajaxurl = 'ajaxDelete.php',
    data = { 'action': clickBtnValue };

    $.post(ajaxurl, data, function (response) { // <-- This function is the callback. It will be executed after the ajax call is done

        if ( clickBtnValue == "Delete Account") {
            $(this).val("yes");
        } else if (clickBtnValue == "yes") {
            $(this).val("Delete Account"); // Useless, because the page is about to be redirected anyway
            window.location.href = 'Functions/LogOut.php';
        } else if (clickBtnValue == "No") {
            $('#delete').val("Delete Account");
        }

    });
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda