Tengo una función que publicará un valor en una página php y luego ejecutará algo de sql. una vez hecho, estoy tratando de establecer la ubicación de la ventana.
Funciona perfectamente si no tengo window.location.href, sin embargo, cuando agrego esta línea de código, cambia la página pero no hace el resto.
$(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"); } }); });Tan pronto como haga clic en el botón, se redirigirá a la página de cierre de sesión. La llamada ajax no tiene tiempo para ejecutarse. Coloque la redirección en la devolución de llamada (que actualmente está vacía)
$('.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"); } }); });