How can PHP and JavaScript work together to efficiently load content on a webpage without reloading the entire page?

To efficiently load content on a webpage without reloading the entire page, PHP can be used to dynamically fetch data from a server and JavaScript can be used to update the content on the page without a full reload. This can be achieved by making an asynchronous request to the server using AJAX in JavaScript, then updating the HTML content on the page based on the response from the server.

<?php
// PHP code to fetch data from the server
$data = fetchDataFromServer();

// Output the data as JSON
echo json_encode($data);
?>