How can JavaScript be integrated with PHP to achieve the desired functionality in this scenario?

To achieve the desired functionality of dynamically updating content on a webpage without refreshing, JavaScript can be integrated with PHP by using AJAX (Asynchronous JavaScript and XML) requests. This allows PHP scripts to be called asynchronously from JavaScript, fetching data from the server and updating the webpage content without a full page reload.

<?php
// PHP script to fetch data and return as JSON
$data = array("message" => "Hello, World!");
echo json_encode($data);
?>