jquery - 使用 sweetalert2 进行软删除的正确方法
问题描述
大家好,我正在使用 sweetalert2,这已经是功能,但有一些错误需要修复。
错误:
当我单击确定时,
location.reload()
将触发而不单击“确定”。当我单击取消时,模式仍处于弹出模式。
这是我的脚本。
$('body').on('click','.delete-category',function(){
deleteCategory();
});
function deleteCategory(id){
var id = $('body').find('#categoryTable tbody tr.selected .catId').val();
console.log(id);
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(function(isConfirm){
if (isConfirm) {
$.ajax({
url: `/asset/category-delete/${id}`,
method: 'DELETE',
data: { _token: '{{ csrf_token()}}' },
success: function(data){
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
location.reload();
},
error: function(err){
swal('Error!','Please report this issue.', 'error');
}
});
} else {
swal("Cancelled","", "error");
}
});
}
寻求增强。
解决方案
关于你的错误 #1:如果你想在 swal 交互之后执行,你必须放置location.reload();
一个方法。then()
success: function(data){
swal(
'Deleted!',
'Your file has been deleted.',
'success'
).then(()=>{
location.reload();
});
},
关于您的错误#2:我无法弄清楚您在说什么“删除模式” ...
推荐阅读
- ios - 用户锁定设备时如何处理 API 请求
- mongodb - 将数据库查询作为微服务 API
- artifactory - 通过 Artifactory REST API 进行高效的服务器端批量删除
- r - R-hub 包检查在“准备构建”时停止
- java - 如何模拟 Kafka RecordMetadata
- google-chrome-extension - Chrome 扩展连接到亚马逊 MWS
- function - 没有从函数 [React Native] 获得任何返回值
- ruby-on-rails - 如何在 Ruby 中获取目录中文件的总大小
- c++ - 高频率插入PostgreSQL,插入数据几分钟后才被选中?
- node.js - 如何自动确定如何在 NodeJS 中裁剪图像?