Reputation: 355
I have created a login form,It POST data to another php page via ajax and check the user name and password validation.If user name or password is wrong it it display the error message on the login form.but If user authentication is OK it should redirect to corresponding page.but now it is loading in side the login form.How to redirect this successfully ?
this is back end logic
if ( password_verify($password, $user['passwrd']) ) {
$userrole=$user['role'];
switch($userrole){
case 'admin':
$_SESSION['username']=$username;
$_SESSION['role']="admin";
// This is how we'll know the user is logged in
$_SESSION['logged_in'] = true;
header('Location: admin-view.php');
break;
This code in front end page
<script type="text/javascript">
var frm= $('#login-form');
frm.submit(function(e){
e.preventDefault();
$.ajax({
type:frm.attr('method'),
url:frm.attr('action'),
data:frm.serialize(),
success:function(data){
$('#feedback').html(data).fadeIn( 300 ).delay( 1500 ).fadeOut( 400 );
},
error:function(data){
console.log('An error occurred !');
console.log(data);
}
});
});
</script>
Upvotes: 0
Views: 1791
Reputation:
you can redirect to another page in javascript like this
window.location.href = "http://stackoverflow.com";
good luck
Upvotes: 0
Reputation: 1579
Right now you are passing the whole page as json data yoou need to relocate to the page like
success:function(data){
if(data==true)
{
window.location.href ="/YourPag.html";
}
);
}
,
Upvotes: 1