What are the best practices for implementing JavaScript to refresh content in PHP without using iFrames?

To refresh content in PHP without using iFrames, you can implement JavaScript to make an AJAX call to a PHP script that retrieves the updated content from the server. This allows for dynamic content updates without having to reload the entire page.

<?php
// PHP code to retrieve and return updated content
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // Retrieve updated content here
    $updatedContent = "This is the updated content";
    
    // Return updated content as JSON
    header('Content-Type: application/json');
    echo json_encode(['content' => $updatedContent]);
}
?>
```

```html
<!-- HTML code to implement JavaScript for content refresh -->
<!DOCTYPE html>
<html>
<head>
    <title>Content Refresh Example</title>
</head>
<body>
    <div id="content"></div>

    <script>
        // JavaScript code to make AJAX call and update content
        function refreshContent() {
            fetch('refresh.php')
                .then(response => response.json())
                .then(data => {
                    document.getElementById('content').innerHTML = data.content;
                })
                .catch(error => console.error('Error:', error));
        }

        // Refresh content every 5 seconds
        setInterval(refreshContent, 5000);

        // Initial content load
        refreshContent();
    </script>
</body>
</html>