gpt4 book ai didi

javascript - 删除前如何在 toastr 中要求确认

转载 作者:行者123 更新时间:2023-12-02 22:11:59 29 4
gpt4 key购买 nike

我正在 PHP LARAVEL 中工作,我想要的是一个 toastr 从数据库中删除项目。因此,当单击按钮进行删除时,toastr 应该询问“您确定要删除吗?”在 Ajax 。如果选择“确定”,则应删除数据,如果选择“取消”,则不应删除数据。如何实现这一点?

下面是我的ajax代码:

//to unfollow feed
$('#following').click(function (e) {

e.preventDefault();
var formData = $("#unfollowFeed").serialize();
$('.error-msg').html('');
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: baseUrl + 'unfollow',
type: 'POST',
data: formData,
success: function (data) {
var id=$('#feed_id').val();
$("#feedId li[feed-id=" + id + "]").remove(); //to remove <li> of removed feed from sidebar.
toastr.error('The feed was removed.');
$('#follow').show();
$('#following').hide();

}

});
});

这是我的观点:

<a href style="{{ $status == 0 ? 'display:none;' : '' }}" class=" btn btn-sm btn-primary following" id="following" >{{ __('Following') }}</a>

谁能帮我解决这个问题吗?

最佳答案

您可以使用Sweetalert Bootstrap

$('#following').click(function (e) {

e.preventDefault();
var formData = $("#unfollowFeed").serialize();
$('.error-msg').html('');
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function() {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: baseUrl + 'unfollow',
type: 'POST',
data: formData,
success: function (data) {
var id=$('#feed_id').val();
$("#feedId li[feed-id=" + id + "]").remove(); //to remove <li> of removed feed from sidebar.
toastr.error('The feed was removed.');
$('#follow').show();
$('#following').hide();

}

});
});
});

关于javascript - 删除前如何在 toastr 中要求确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59527754/

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