Вот базовый пример использования AJAX с PHP:
- 
HTML-разметка:
<!DOCTYPE html> <html> <head> <title>AJAX PHP Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#submit_btn").click(function() { var name = $("#name").val(); // Get the value from the input field $.ajax({ url: "process.php", // PHP file for processing the data type: "POST", data: {name: name}, // Data to be sent to the server success: function(response) { $("#result").html(response); // Display the response from the server } }); }); }); </script> </head> <body> <input type="text" id="name" placeholder="Enter your name"> <button id="submit_btn">Submit</button> <div id="result"></div> </body> </html> - 
Обработка PHP (process.php):
<?php if(isset($_POST['name'])) { $name = $_POST['name']; // Process the data or perform any desired operations // For example, you can store the name in a database or perform some calculations // Return a response to the AJAX request echo "Hello, " . $name . "! Your name has been processed successfully."; } ?> 
В этом примере, когда пользователь вводит свое имя и нажимает кнопку «Отправить», запрос AJAX отправляется серверному PHP-скрипту (process.php) с данными имени. Сценарий PHP обрабатывает данные и отправляет ответ обратно клиентскому JavaScript, который затем обновляет HTML-страницу ответом.