Are there any specific best practices to follow when using JavaScript to display loading status messages in PHP applications?

When using JavaScript to display loading status messages in PHP applications, it is best practice to use AJAX to asynchronously communicate with the server and update the loading status on the client side. This helps improve the user experience by providing real-time feedback during long-running processes.

// PHP code snippet to handle AJAX request for displaying loading status message
if(isset($_POST['action']) && $_POST['action'] == 'display_loading_status'){
    // Perform long-running process here
    echo json_encode(['status' => 'loading']);
    exit;
}