<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Тестовое задание</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Форма отправки</h1>
<div class="form">
<form action="" method="post" name="post_data">
<input id="name" type="text" name="name" placeholder="Имя" required="required"></input>
<input id="surname" type="text" name="surname" placeholder="Фамилия" required="required"></input>
<input id="tel" type="tel" name="tel" placeholder="+994XXXXXXXXX" required="required"></input>
<input id="email" type="email" name="email" placeholder="example@example.com" required="required"></input>
<textarea id="text" name="text" placeholder="Сообщение"></textarea>
<input id="submit" type="submit" value="Отправить данные"></input>
</form>
</div>
<div class="form">
<form action="" method="get" name="get_data">
<input id="get" type="submit" value="Получить данные">
<div id="output">
</div>
</form>
</div>
<script src="jquery-3.3.1.min.js"></script>
<script src="form.js"></script>
</body>
</html>
$(document).ready(function(){
//POST Function
$('form[name="post_data"]').on('#post', function(event) {
event.preventDefault();
$.ajax({
url: 'post.php',
method: 'POST',
data: $(this).serialize(),
success: function() {
alert('Успех!');
},
error: function() {
alert('Ошибка!');
}
});
});
//GET Function
$('form[name="get_data"]').on('#get', function() {
$.ajax({
url: 'get.php',
method: 'GET',
success: function(response) {
$("#output").html(response);
}
});
});
});
<?php
$connection = mysqli_connect("localhost", "root", "", "te_database");
$result = mysqli_query("SELECT * FROM data", $connection);
$row = mysqli_fetch_array($result);
{
print $row['id', 'name', 'surname', 'tel', 'email', 'text']."<br>";
}
?>
$.ajax({
//?
});