Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!