I’m validating a form using jQuery and against a database using PHP-MySQL. The AJAX call is successful but the current page(A) is not redirected to page(B) after successful validation. But if i refresh the page, the page(B) is loaded. That is, the call is successful but jQuery is not redirecting.
<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>
I also tried replacing document.location with window.location and window.location.href and window.location.replace(….) but even they dont work. Someone please help.
the problem must be one of these 2 or both:
1) The data that ajax returns is not equal to ‘yes’
2)ajax is not successful and it has error
please check that if the ajax is successful and then return value is equal to ‘yes’