Я смог отправить данные при нажатии кнопки подтверждения.
однако, когда нажата кнопка отмены sweetalert2 показывает, как успешно вставил данные.
назад-end показывает как пустую строку. (в таблице базы данных)
, как проверить, когда я нажал кнопку отмены, чтобы не отправлять данные на сервер.
Javascript function
function inputPass(complaintID) { // complaint id pass is ok.
swal({
text: 'Input comment message',
input: 'textarea',
showCancelButton: true,
}).then(function(sample_text) {
console.log(sample_text);
if(sample_text === '') { // problem is here.
swal({
type: 'warning',
html: 'cannot proceed without input'
});
} else {
console.log(sample_text);
$.ajax({
type: "POST",
url: "../ajax/ajax_active_deact.php?type=complaint_answered",
data: {complaintID: complaintID, sampleText: sample_text}
}).done(function (res) {
if(!res) {
swal({
type: 'error',
html: 'insert the valid text'
});
} else {
swal({
title: 'done',
text: 'all right',
type: 'success',
allowOutsideClick: false,
confirmButtonText: 'Ok'
});
}
});
}
});
}
php ajax code
function complaint_answered() {
include_once('../backend/ConsumerComplaint.php');
$con_complaint = new ConsumerComplaint();
$res = $con_complaint>mark_as_answered($_POST['complaintID'],$_POST['sampleText']);
echo $res;
}
Это моя функция класса
function mark_as_answered($id, $comment) {
//var_dump($comment);
$val = $comment['value']; // $comment is a associative array, with the key of 'value'
$sql = "UPDATE c_consumer_complaint SET `status` = 'answered', `update` = '$val'
WHERE complaint_id = '$id' ";
$res = $this->conn->query($sql);
return $res;
}
- изображение, когда я нажимал кнопку отмены на сетевой панели в хроме

- изображение консоли

- изображение данных поста в хроме

Я новичок в разработкеи не могу обойти, как решить эту проблему.пожалуйста, кто-нибудь может дать мне то, что я делаю не так здесь.Thnks!