Pass JavaScript Object from Ajax to PHP

Create new php file named ajax.php as below:

<?php 
    $student = $_POST['student'];
    print_r($student);
    echo '<br>id: '.$student['id'];
    echo '<br>name: '.$student['name'];
    echo '<br>age: '.$student['age'];
?> 

Create new php file named index.php as below:

<html>

    <head>
        <title>nilpointer.net</title>
        <script src="js/jquery-3.6.0.min.js"></script>
        <script>
            $(document).ready(function() {

                $('#buttonDemo').click(function() {
                    $.ajax({
                        type: 'POST',
                        data: {
                            student: {
                                id: 'st01',
                                name: 'name 1',
                                age: 20
                            }
                        },
                        url: 'ajax.php',
                        success: function(data) {
                            $('#result').html(data);
                        }
                    });
                });

            });
        </script>
    </head>

    <body>

        <input type="button" value="Demo Ajax" id="buttonDemo">
        <br>
        <span id="result"></span>

    </body>

</html>