Sweet alert 在用户点击 OK 之前重定向
Sweet alert redirects before the user clicks OK
我正在使用 SweetAlert2 和本页的第 7 个示例:
Go to 7th example below to see it in action
这个:
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';
}
});
});
}
但是当用户点击确认按钮删除....这个弹窗
由于我的重定向,用户甚至没有机会单击“确定”按钮...
如何在用户点击此图片上的“确定”后进行重定向?
我终于自己解决了这个问题:
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';
});
});
});
}
我正在使用 SweetAlert2 和本页的第 7 个示例:
Go to 7th example below to see it in action
这个:
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';
}
});
});
}
但是当用户点击确认按钮删除....这个弹窗
由于我的重定向,用户甚至没有机会单击“确定”按钮...
如何在用户点击此图片上的“确定”后进行重定向?
我终于自己解决了这个问题:
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';
});
});
});
}