2011-12-24 122 views
0

我使用jQuery和使用PHP-MySQL的數據庫驗證表單。 AJAX調用成功,但當前頁面(A)在成功驗證後未重定向到頁面(B)。但是,如果我刷新頁面,頁面(B)被加載。也就是說,調用成功,但jQuery不重定向。jQuery在AJAX調用後不重定向

<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,但即使他們不工作。有人請幫忙。

+0

所謂的jQuery重定向不存在。 – 2011-12-24 11:31:35

+1

怎麼樣'document.location.href'? :-P – Quasdunk 2011-12-24 11:31:53

+0

msg'元素是否會像它應該消失? – Cyclonecode 2011-12-24 11:33:18

回答

1

問題必須是一個這些2或兩者:

1)的數據表明,AJAX返回不等於「是」

2)AJAX是沒有成功,並且它的主要錯誤

請檢查,如果ajax成功,然後返回值等於'是'