Javascript 调用window.location.href时Jquery未正确执行
我有一个函数,可以将一个值发布到php页面,然后运行一些sql。 完成后,我尝试设置窗口位置 如果我没有window.location.href,它可以完美地工作,但是当我添加这行代码时,它会更改页面,但不会执行其余操作Javascript 调用window.location.href时Jquery未正确执行,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个函数,可以将一个值发布到php页面,然后运行一些sql。 完成后,我尝试设置窗口位置 如果我没有window.location.href,它可以完美地工作,但是当我添加这行代码时,它会更改页面,但不会执行其余操作 $(document).ready(function () { $('.delete').click(function () { $('.confirm').
$(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");
}
});
});
单击按钮后,立即重定向到注销页面。ajax调用没有时间执行。 将重定向放入回调(当前为空)
$('.delete')。单击(函数(){
$('.confirm').toggleClass('confirmShow');
var clickBtnValue=$(this.val();
var ajaxurl='ajaxDelete.php',
数据={'action':单击BtnValue};
$.post(ajaxurl,数据,函数(response){//在callback中执行这些操作我如何执行回调?@MichaelGrinnell您已经有了一个回调函数,$中的函数。post
以response
作为参数。将post请求之后应该发生的所有事情都放在那里。
$('.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");
}
});
});