How can PHP handle data submission via page reload versus Ajax requests?

When handling data submission via page reload, PHP can use the $_POST superglobal to access form data. On the other hand, when using Ajax requests, PHP can utilize the $_REQUEST superglobal to handle both POST and GET data. By checking the request method in PHP, you can determine whether the data is being submitted via page reload or Ajax request and process it accordingly.

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Handle form submission via page reload
    $data = $_POST['data'];
    
    // Process the data as needed
    // For example, save it to a database or perform some calculations
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // Handle Ajax request
    $data = $_REQUEST['data'];
    
    // Process the data as needed
    // For example, return a JSON response
}