【发布时间】:2017-09-04 09:59:39
【问题描述】:
您好,我是使用甜美警报 js 使我的警报框更加精美的新手。我正在使用普通的 javascript 警报确认来删除表中的特定数据。但是,当我尝试在删除它之前运行一个甜蜜的警报确认时,会删除文件而不会弹出确认。
下面是我的 JS 中的代码。
<script>
archiveFunction() {
swal({
title: "Are you sure?",
text: "But you will still be able to retrieve this file.",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, archive it!",
cancelButtonText: "No, cancel please!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been archived.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
}
</script>
这是我下面的 html 表单。
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="p_id" id="p_id" value="<?php echo $rows['p_id']; ?>">
<button class="btn btn-danger" type="submit" name="archive" onclick="archiveFunction()">
<i class="fa fa-archive"></i>
Archive
</button>
</form>
这是php中的代码。
<?php
include('../config.php');
if(isset($_POST['archive']))
{
$p_id = $_REQUEST['p_id'];
// sql to delete a record
$sqli = "UPDATE students SET archive = 2 WHERE p_id=$p_id";
if ($conn->query($sqli) === TRUE) {
echo "swal('Archived!', 'Click ok to see!', 'success')";
} else {
echo "Error Archiving record: " . $conn->error;
}
$conn->close();
}
?>
我想要发生的是在删除特定数据之前确认甜蜜警报确认。
【问题讨论】:
标签: javascript php jquery sweetalert