1 回答

TA贡献1817条经验 获得超6个赞
在我看来,您实际上从未将任何数据发送回服务器。
内置的 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>
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报