删除确认 HREF Sweet Alert
Delete confirmation HREF Sweet Alert
但我似乎无法用该论坛的相同逻辑解决这个问题。
我正在开发一个预订模块,它有一个功能是确认还是取消一个预订。这是我的 PHP
代码,用于显示预订是已确认、已取消还是尚未确认。 Status==0
(尚未确认)- 默认一个,Status==1
(已确认)和 Status==2
(已取消)
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:index.php');
}
else{
if(isset($_REQUEST['eid']))
{
$eid=intval($_GET['eid']);
$status="2";
$sql = "UPDATE tblbooking SET Status=:status WHERE id=:eid";
$query = $dbh->prepare($sql);
$query -> bindParam(':status',$status, PDO::PARAM_STR);
$query-> bindParam(':eid',$eid, PDO::PARAM_STR);
$query -> execute();
$msg="Booking Successfully Cancelled";
}
if(isset($_REQUEST['aeid']))
{
$aeid=intval($_GET['aeid']);
$status=1;
$sql = "UPDATE tblbooking SET Status=:status WHERE id=:aeid";
$query = $dbh->prepare($sql);
$query -> bindParam(':status',$status, PDO::PARAM_STR);
$query-> bindParam(':aeid',$aeid, PDO::PARAM_STR);
$query -> execute();
$msg="Booking Successfully Confirmed";
}
<?php $sql = "SELECT tblbooking.Status";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0){
foreach($results as $result){
?>
if($result->Status==0){
echo htmlentities('Not Confirmed yet');
} else if ($result->Status==1) {
echo htmlentities('Confirmed');
}
else{
echo htmlentities('Cancelled');
}
这是原始代码,它将 confirm/cancel 带有基本 Javascript
警报的预订
<td><button class="btn btn-sm btn-primary"><a href="manage-bookings.php?aeid=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you really want to Confirm this booking')"> <i style="color: #fff;" class='fa fa-check'></i></a></button>
<button class="btn btn-sm btn-danger"><a href="manage-bookings.php?eid=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you really want to Cancel this booking')"> <i style="color: #fff;" class='fa fa-close'></i></a></button></td>
但我想使用 sweetalert,所以我将其修改为这个(先用锚点进行测试)
<a href="manage-bookings.php?aeid=<?php echo htmlentities($result->id);?>" onclick="confirmation(event)">Confirm</a>
这是 script
<script>
function confirmation(ev) {
ev.preventDefault();
var urlToRedirect = ev.currentTarget.getAttribute('href'); //use currentTarget because the click may be on the nested i tag and not a tag causing the href to be empty
console.log(urlToRedirect); // verify if this is the right URL
swal({
title: "Are you sure you want to tag this booking as confirmed",
text: "You will not be able to revert this!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
// redirect with javascript here as per your logic after showing the alert using the urlToRedirect value
if (willDelete) {
swal("Your booking as been confirmed!", {
icon: "success",
});
} else {
swal("You booking hasn't been confirmed.");
}
});
}
</script>
The problem is, the alert works. It creates a pop up confirmation but it doesn't confirm/cancel the booking at all although the href
links says the same thing with the original but the original reloads the page and the tagging works.
在我看来,您实际上从未将任何数据发送回服务器。
内置的 javascript 确认对话框会中断您的超链接,然后在您点击“确定”后允许它恢复。
Sweetalerts 似乎没有这样做。因此,您永远不会重定向到您需要访问的页面。您可以使用 javascript 重定向到正确的 URL 或者,您可以为您尝试执行的操作编写服务器端 API,并从中调用 API AJAX 在 'willDelete' 案例中。
这是前一个选项:
<script>
function confirmation(ev) {
ev.preventDefault();
var urlToRedirect = ev.currentTarget.getAttribute('href'); //use currentTarget because the click may be on the nested i tag and not a tag causing the href to be empty
console.log(urlToRedirect); // verify if this is the right URL
swal({
title: "Are you sure you want to tag this booking as confirmed",
text: "You will not be able to revert this!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
// redirect with javascript here as per your logic after showing the alert using the urlToRedirect value
window.location.href = urlToRedirect;
} else {
swal("You booking hasn't been confirmed.");
}
});
}
</script>
但我似乎无法用该论坛的相同逻辑解决这个问题。
我正在开发一个预订模块,它有一个功能是确认还是取消一个预订。这是我的 PHP
代码,用于显示预订是已确认、已取消还是尚未确认。 Status==0
(尚未确认)- 默认一个,Status==1
(已确认)和 Status==2
(已取消)
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:index.php');
}
else{
if(isset($_REQUEST['eid']))
{
$eid=intval($_GET['eid']);
$status="2";
$sql = "UPDATE tblbooking SET Status=:status WHERE id=:eid";
$query = $dbh->prepare($sql);
$query -> bindParam(':status',$status, PDO::PARAM_STR);
$query-> bindParam(':eid',$eid, PDO::PARAM_STR);
$query -> execute();
$msg="Booking Successfully Cancelled";
}
if(isset($_REQUEST['aeid']))
{
$aeid=intval($_GET['aeid']);
$status=1;
$sql = "UPDATE tblbooking SET Status=:status WHERE id=:aeid";
$query = $dbh->prepare($sql);
$query -> bindParam(':status',$status, PDO::PARAM_STR);
$query-> bindParam(':aeid',$aeid, PDO::PARAM_STR);
$query -> execute();
$msg="Booking Successfully Confirmed";
}
<?php $sql = "SELECT tblbooking.Status";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0){
foreach($results as $result){
?>
if($result->Status==0){
echo htmlentities('Not Confirmed yet');
} else if ($result->Status==1) {
echo htmlentities('Confirmed');
}
else{
echo htmlentities('Cancelled');
}
这是原始代码,它将 confirm/cancel 带有基本 Javascript
警报的预订
<td><button class="btn btn-sm btn-primary"><a href="manage-bookings.php?aeid=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you really want to Confirm this booking')"> <i style="color: #fff;" class='fa fa-check'></i></a></button>
<button class="btn btn-sm btn-danger"><a href="manage-bookings.php?eid=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you really want to Cancel this booking')"> <i style="color: #fff;" class='fa fa-close'></i></a></button></td>
但我想使用 sweetalert,所以我将其修改为这个(先用锚点进行测试)
<a href="manage-bookings.php?aeid=<?php echo htmlentities($result->id);?>" onclick="confirmation(event)">Confirm</a>
这是 script
<script>
function confirmation(ev) {
ev.preventDefault();
var urlToRedirect = ev.currentTarget.getAttribute('href'); //use currentTarget because the click may be on the nested i tag and not a tag causing the href to be empty
console.log(urlToRedirect); // verify if this is the right URL
swal({
title: "Are you sure you want to tag this booking as confirmed",
text: "You will not be able to revert this!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
// redirect with javascript here as per your logic after showing the alert using the urlToRedirect value
if (willDelete) {
swal("Your booking as been confirmed!", {
icon: "success",
});
} else {
swal("You booking hasn't been confirmed.");
}
});
}
</script>
The problem is, the alert works. It creates a pop up confirmation but it doesn't confirm/cancel the booking at all although the
href
links says the same thing with the original but the original reloads the page and the tagging works.
在我看来,您实际上从未将任何数据发送回服务器。
内置的 javascript 确认对话框会中断您的超链接,然后在您点击“确定”后允许它恢复。
Sweetalerts 似乎没有这样做。因此,您永远不会重定向到您需要访问的页面。您可以使用 javascript 重定向到正确的 URL 或者,您可以为您尝试执行的操作编写服务器端 API,并从中调用 API AJAX 在 'willDelete' 案例中。
这是前一个选项:
<script>
function confirmation(ev) {
ev.preventDefault();
var urlToRedirect = ev.currentTarget.getAttribute('href'); //use currentTarget because the click may be on the nested i tag and not a tag causing the href to be empty
console.log(urlToRedirect); // verify if this is the right URL
swal({
title: "Are you sure you want to tag this booking as confirmed",
text: "You will not be able to revert this!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
// redirect with javascript here as per your logic after showing the alert using the urlToRedirect value
window.location.href = urlToRedirect;
} else {
swal("You booking hasn't been confirmed.");
}
});
}
</script>