window.location不使用Ajax重定向



我有一个页面,其中包含几个使用Ajax的用户控件。当我尝试从这个页面执行window.location时,Ajax会捕获调用,并且不允许重定向

$.ajax({
url: 'assets/php/action.php',
method: 'post',
data: $("#register-form").serialize()+'&action=register',
success:function(response){
$("#register-btn").val('Sign Up');
//   console.log(response);
if(response === 'register'){
alert("you will now be redirected");
window.location = 'home.php';
}
else{ 
$("#regAlert").html(response);
}
}
});

使用这个而不是window.location.href = 'home.php';

最新更新