gpt4 book ai didi

javascript - Sweet alert 在用户点击 OK 之前重定向

转载 作者:行者123 更新时间:2023-11-29 16:46:30 27 4
gpt4 key购买 nike

我正在使用 SweetAlert2 并希望将用户重定向到不同的页面,但是在成功警报和用户单击“确定”之后。

这个:

    swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
},
function() {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
});

像这样:

function deleteEvent(id)
{
swal({
title: 'Are you sure?',
text: 'You will not be able to recover this event!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
}).then(function() {
swal(
'Deleted!',
'Your event has been deleted.',
'success'
);
$.ajax({
url: '/events/'+id,
type: "DELETE",
data:{ _token: "{{csrf_token()}}" },
success: function() {
location.href = '/events';
}
});
});
}

但是当用户点击确认按钮删除....这个弹窗 enter image description here

由于我的重定向,用户甚至没有机会点击 OK 按钮...

在用户点击此图片上的“确定”后,如何进行重定向?

最佳答案

我终于自己解决了这个问题:

function deleteEvent(id)
{
swal({
title: 'Are you sure?',
text: 'You will not be able to recover this event!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: false
}).then(function() {

$.ajax({
url: '/events/'+id,
type: "DELETE",
data:{ _token: "{{csrf_token()}}" }
}).done(function() {

swal({
title: "Deleted",
text: "Event has been successfully deleted",
type: "success"
}).then(function() {
location.href = '/events';
});
});
});
}

关于javascript - Sweet alert 在用户点击 OK 之前重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40628636/

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