php - AJAX 调用后 jQuery 未重定向

标签 php mysql jquery

我正在使用 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/

相关文章:

jquery - 更改asp :label with jQuery then access in codebehind

json - JavaScript : Array overriding the same values after assinging to JSON object

php - 最简单的 Javascript If 语句不起作用

php - Mysqli Prepare 语句 - 返回 False,但为什么?

mysql - mysql如何获取前3个值?罗斯文数据库

sql - MySQL截断命令-unicode字符

validation - Jquery 验证插件和 Colorbox

php - eclipse PHP Zend : "workspace in use" when i try to set my workspace in Apache2/htdocs?

php - wordpress 博客文章缩略图的图像灰度

mysql - 如何清除/刷新 mysql innodb 缓冲池?