I am using ajax to post in the login part and create session. the session is working but in there header('location: chat.php') is not working(not redirected). while I am trying to log in session is created but not redirected to chat.php. I checked jQuery and ajax is working and successful to create a session and log in but not redirected to chat.php. Can any help me plz
jQuery('.userlogin').submit(function(){
            var email = jQuery("input[name='email_address']").val();
            var password = jQuery("input[name='password']").val();
            $.ajax({
                'url'   : 'login.php',
                'type'  : 'POST',
                'data'  : {
                    'loginajax' : '',
                    'email'     : email,
                    'password'  : password
                },
                'success'  : function(output){
                    jQuery('.ama-input').val('');
                }
            });
        });
<?php
session_start();
require_once('functions.php');
if(isset($_POST['loginajax'])){
    $email=$_POST['email'];
    $password=$_POST['password'];
    $query = mysqli_query($connection, "SELECT * FROM users WHERE email='$email'");
    $info = mysqli_fetch_assoc($query);
    $pass= $info['password'];
    if($pass==md5($password)){
        $_SESSION['login'] = "successful";
        header('location: chat.php');
    }
    die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Log In</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="box">
        <h2 class="heading">Log In</h2>
        <form action="" method="POST" class="userlogin">
            <input class="ama-input" type="email" name="email_address" placeholder="Email Address" />
            <input class="ama-input" type="password" name="password" placeholder="Password" />
            <input type="submit" name="login" value="Log In" />
        </form>
        <a class="registration" href="register.php">Create an account</a><br />
    </div>
    <script src="js/jquery-3.5.1.min.js"></script>
    <script src="js/script.js"></script>
</body>
</html>
 
     
    