lew*_*s4u 2 javascript sweetalert
我正在使用此页面上的SweetAlert2和第7个示例:
这个:
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'
);
});
Run Code Online (Sandbox Code Playgroud)
像这样:
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';
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
由于我的重定向而立刻离开,用户甚至没有机会点击确定按钮...
如何在用户单击此图像上的"确定"后进行重定向?
我终于解决了这个问题:
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';
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4297 次 |
| 最近记录: |