gpt4 book ai didi

javascript - 单击 Sweet Alert 按钮后调用 php 文件

转载 作者:行者123 更新时间:2023-12-03 00:13:22 25 4
gpt4 key购买 nike

我试图在单击甜蜜警报中的按钮后调用 php 文件。该功能是登录账户的确认。示例过程是当您注销事件帐户时,会弹出一条消息,这是甜蜜的警报,如果您单击“确定”按钮,那么它应该已经破坏了用户的 session 。有人可以帮我弄这个吗?

这是我的代码:

<a href="javascript:swal({title:'Logout', 
text:'Do you want to logout this Account?'
, icon:'warning',
buttons: true,
dangerMode: true}).then((willOUT) => {
if (willOUT) {
url: 'page_logout.php', {
icon: 'success',
});
}
});"
class="nav-item dropdown-item">
Log out
</a>

see the console

最佳答案

这会对你有帮助。它可以带您到 page_logout.php您在

中编写的 swal 代码中也存在一些错误
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="#" id="a_id">Logout</p>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#a_id").click(function(){

swal({title:'Logout',
text:'Do you want to logout this Account?',
icon:'warning',
buttons: true,
dangerMode: true
})
.then((willOUT) => {
if (willOUT) {
window.location.href = 'page_logout.php', {
icon: 'success',
}
}
});

});
});
</script>
</body>
</html>

或者,如果您想在有注销按钮的同一页面中显示消息,则可以对 page_logout.php 执行 ajax 请求,而不是问题中的 url。希望对您有帮助。

关于javascript - 单击 Sweet Alert 按钮后调用 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54624240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com