<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
// Process the data or perform any backend tasks
// ...
// Return a response back to the frontend
$response = [
"status" => "success",
"message" => "Data received successfully!"
];
header("Content-Type: application/json");
echo json_encode($response);
}
?>
This code snippet checks if the HTTP request method is "POST". If it is, it retrieves the values of the "name" and "email" parameters from the request body and assigns them to the variables $name and $email respectively.
The code snippet declares an associative array assigned to the variable $response, which contains the status and message keys with their respective values.
The code sets the HTTP response header to specify that the content being returned is in JSON format, and then it encodes the $response array as JSON and echoes it to the response body.