Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除确认HREF甜蜜警报_Javascript_Php_Sweetalert - Fatal编程技术网

Javascript 删除确认HREF甜蜜警报

Javascript 删除确认HREF甜蜜警报,javascript,php,sweetalert,Javascript,Php,Sweetalert,但我似乎无法用那个论坛的同样逻辑来解决这个问题 我正在处理一个预订模块,它有一个功能是确认预订还是取消预订。这是我的PHP代码,它告诉我预订是否已确认、取消或尚未确认状态==0(尚未确认)-默认值,状态==1(已确认)和状态==2(已取消) 但我想使用sweetalert,所以我将其修改为(首先使用anchor进行测试) 问题是,警报起作用了。它创建了一个弹出式确认,但它根本不确认/取消预订,尽管href链接对原始内容说了同样的话,但原始内容会重新加载页面,并且标签会起作用 在我看来,您从未真正

但我似乎无法用那个论坛的同样逻辑来解决这个问题

我正在处理一个预订模块,它有一个功能是确认预订还是取消预订。这是我的
PHP
代码,它告诉我预订是否已确认、取消或尚未确认<代码>状态==0(尚未确认)-默认值,
状态==1
(已确认)和
状态==2
(已取消)

但我想使用sweetalert,所以我将其修改为(首先使用anchor进行测试)

问题是,警报起作用了。它创建了一个弹出式确认,但它根本不确认/取消预订,尽管
href
链接对原始内容说了同样的话,但原始内容会重新加载页面,并且标签会起作用


在我看来,您从未真正将任何数据发送回服务器

内置的javascript确认对话框会中断您的超链接,然后在您点击OK后允许它继续

看来Sweetalerts并没有这样做。因此,您永远不会重定向到需要访问的页面。您可以使用javascript重定向到正确的URL,或者,您可以为尝试执行的操作编写一个服务器端API,并在“willDelete”案例中从AJAX调用该API

前一种选择是:

<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>

功能确认(ev){
ev.preventDefault();
var urlToRedirect=ev.currentTarget.getAttribute('href');//使用currentTarget,因为单击可能在嵌套的i标记上,而不是导致href为空的标记上
console.log(urlToRedirect);//验证这是否是正确的URL
游泳({
标题:“您确定要将此预订标记为已确认”,
文本:“您将无法还原此内容!”,
图标:“警告”,
按钮:是的,
丹格莫德:没错,
})
。然后((将删除)=>{
如果(将删除){
//在使用urlToRedirect值显示警报后,根据您的逻辑在此处使用javascript重定向
window.location.href=urlToRedirect;
}否则{
swal(“您的预订尚未确认。”);
}
});
}

除了通知之外,我看不到您对选择做任何事情的部分。您是否如评论中所述重定向到
urlToRedirect
?谢谢!我完全忽略了这一点,它现在可以工作了:)也有可能行ev.currentTarget.getAttribute('href');应为ev.target.offsetParent.children[0].href;非常感谢。成功了!即使使用
ev.currentTarget.getAttribute('href')
<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>
<a href="manage-bookings.php?aeid=<?php echo htmlentities($result->id);?>" onclick="confirmation(event)">Confirm</a>
<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>
<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>