How can JavaScript be integrated with PHP to perform background data queries without page reloading in PHP applications?

To perform background data queries without page reloading in PHP applications, JavaScript can be integrated with PHP using AJAX (Asynchronous JavaScript and XML) requests. This allows JavaScript to send a request to a PHP script in the background, retrieve data without reloading the page, and update the content dynamically.

<?php
// PHP script to handle AJAX request
if(isset($_POST['data'])){
    // Process data and perform queries
    $data = $_POST['data'];
    
    // Return data as JSON
    echo json_encode($result);
}
?>