What is the recommended approach for displaying information on a website when hovering over a name using PHP?

When hovering over a name on a website, it is common to display additional information about that person. One recommended approach to achieve this using PHP is to use AJAX to fetch the additional information from the server when the name is hovered over, and then display it dynamically on the webpage without refreshing the entire page.

<?php
// PHP code to fetch additional information about a person when hovering over their name
if(isset($_GET['person_id'])) {
    $person_id = $_GET['person_id'];
    
    // Perform a database query or any other operation to fetch additional information based on the person_id
    
    // Return the additional information in JSON format
    $additional_info = [
        'name' => 'John Doe',
        'age' => 30,
        'occupation' => 'Engineer'
    ];
    
    echo json_encode($additional_info);
    exit;
}
?>