我正在使用 jQuery 验证表单并使用 PHP-MySQL 验证数据库。 AJAX调用成功,但验证成功后当前页面(A)并未重定向到页面(B)。但是如果我刷新页面,页面(B)就会被加载。即调用成功但 jQuery 没有重定向。
<script language="javascript">
$(document).ready(function()
{
$("#login_form").submit(function()
{
//remove all the class add the messagebox classes and start fading
$("#msg").text('Checking....').fadeIn(1000);
//check the username exists or not from ajax
$.post("signin_check.php",{ loginid:$('#username').val(),pswd:$('#password').val() }, function(data)
{
if(data=='yes') //if correct login detail
{
$("#msg").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).text('Logging in.....').fadeTo(900,1,
function(){
//redirect to secure page
document.location = "/pawn/selectdomain.php";
});
});
}
else
{
$("#msg").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).text('Incorrect login details !!').fadeTo(900,1);
});
}
});
return false; //not to post the form physically
});
//now call the ajax also focus move from
$("#password").blur(function()
{
$("#login_form").trigger('submit');
});
});
</script>
我还尝试用 window.location 和 window.location.href 和 window.location.replace(....) 替换 document.location,但即使它们也不起作用。请有人帮忙。
最佳答案
问题必须是以下两个之一或两者兼而有之:
1)ajax返回的数据不等于'yes'
2)ajax不成功,有错误
请检查ajax是否成功,然后返回值是否等于“yes”
关于php - AJAX 调用后 jQuery 未重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8624248/