Добрый вечер всем!
Приходят данные с кнопки формы, но данные с ajax нет.
Получаю вот такие данные:
action close
id 1
Код страницы
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Просмотр заявки</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
<?php require_once ('includes/db.php') ?>
<script type="text/javascript" src="module/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function(){
$("#rat").submit(function(){
var ocenka = prompt ("Введите текст: ")
$.ajax({
url:"includes/functions.php",
type:"POST",
data:({rat: ocenka, action: "close"}),
dataType: "html"
});
});
});
</script>
</head>
<body>
<?php require_once ('includes/header.php'); ?>
<?php
$qr_result = mysqli_query($connection, "SELECT * FROM `applications` WHERE `id` = " . (int) $_GET['id']);
$data = mysqli_fetch_assoc($qr_result);
?>
<form action="includes/functions.php" method="POST">
<form action="includes/functions.php" method="POST">
<div class="buttons">
<input type="hidden" name="action" value="delete" />
<input type="hidden" name="id" value=<?php echo $_GET['id'] ?> />
<input type="submit" value="Удалить заявку" />
</div>
</form>
<form action="includes/functions.php" method="POST">
<div>
<input type="hidden" name="action" value="close" />
<input type="hidden" name="id" value=<?php echo $_GET['id'] ?> />
<input type="submit" id="rat" value="Закрыть заявку" />
</div>
</form>
<div class="head">
<label class="bold"> Cтатус заявки </label> </br>
<label id = "change"> <?php echo $data['status']; ?> </label></br></br>
</div>
<div class="head">
<label class="bold"> Тема заявки </label> </br>
<label> <?php echo $data['theme']; ?> </label></br></br>
</div>
<div class="head">
<label> Описание </label> </br>
<label> <?php echo $data['text']; ?> </label></br></br>
</div>
<div class="head">
<label class="bold"> Назначено </label> </br>
<form action="includes/functions.php" method="POST">
<?php require_once ('includes/db.php');
$usersel = mysqli_query($connection, "SELECT * FROM `user`");
echo "<select id='selUser' name = 'selUser'>";
while ($data =mysqli_fetch_assoc($usersel)){
echo '<option>' . $data['fullname'] . '</option>';
}
echo "<input type = 'hidden' name = 'action' value='update'>";
echo "<input type = 'hidden' name = 'id' value='" . $_GET['id'] . "'>";
echo "<input type = 'submit' value = 'Принять'></select>";
?>
</form>
</br></br>
</div>
</form>
</body>
</html>
Код страницы обработчика
<?php
$location = '/';
echo "Ocenka: " . $_POST['rat'] . "</br>";
if (isset($_POST['action']))
{
require_once('db.php');
$query = '';
switch($_POST['action'])
{
case 'addApp':
$theme = $_REQUEST['theme'];
$text = $_REQUEST['text'];
$query = "INSERT INTO `applications` (`theme`, `text`) VALUE('$theme', '$text')";
break;
case 'delete':
$query = "DELETE FROM `applications` WHERE `id` = " . $_POST['id'];
break;
case 'addUser';
$fullname = $_REQUEST['fullname'];
$query = "INSERT INTO `user` (`fullname`) VALUE('$fullname')";
break;
case 'update';
$query = "UPDATE `applications` SET `associate` = '" . $_POST['selUser'] . "' WHERE `id` = " . $_POST['id'];
break;
case 'close';
$query = "UPDATE `applications` SET `status` = 'Закрыта' `assessment` = ". $_POST['rat'] . " WHERE `id` = " . $_POST['id'];
break;
}
if (!empty($query)) mysqli_query($connection, $query);
}
print_r($query);
//header ('Location: ' . $location);
exit();