javascript - SweetAlert2 : 配置我的警报的一些困难
问题描述
我正在尝试使用 sweetAlert2。https://sweetalert2.github.io/
计划如下:
1) 主警报的显示
2)如果他点击“取消”,我会正常关闭警报。
3) 如果他点击“确定”,按钮会转到加载位置,但警报不会关闭。与此同时,我提出了一个 Ajax 请求。当它结束时,我才能关闭第一个警报并查看第二个警报。
4)当我在第二个警报上单击“确定”时,页面重新加载。
但是目前我无法很好地管理如何在单击“确定”和“取消”时显示警报。
我在下面有这段代码:
Swal.fire({
title: 'Change to '+planName,
text: message,
icon: "info",
showCancelButton: true,
showLoaderOnConfirm: true,
preConfirm: function () {
// todo - actually change the plan!
$.ajax({
url: changeUrl,
method: 'POST'
}).done(function(){
Swal.fire({
title: 'Plan changed !',
icon: 'success',
},function() {
location.reload();
})
});
}
});
当我在第一个警报上单击 CANCEL 时,一切都很顺利。但是,如果我单击“确定”,我会看到确认按钮进入“加载程序”,但警报直接关闭。然后发出我的 Ajax 请求,然后显示第二个警报。
有人可以帮我吗?
编辑:当前代码:
Swal.fire({
title: 'Change to '+planName,
text: message,
icon: "info",
showCancelButton: true,
showLoaderOnConfirm: true,
preConfirm: function () {
// todo - actually change the plan!
return $.ajax({
url: changeUrl,
method: 'POST'
}).done(function(){
Swal.fire({
title: 'Plan changed !',
icon: 'success',
},function() {
location.reload();
})
});
}
});
解决方案
这样做怎么样
Swal.fire({
title: 'Change to '+planName,
text: message,
icon: "info",
showCancelButton: true,
showLoaderOnConfirm: true,
preConfirm: function () {
// todo - actually change the plan!
return $.ajax({
url: changeUrl,
method: 'POST'
}).done(function(){
Swal.fire({
title: 'Plan changed !',
icon: 'success',
},function() {
location.reload();
})
});
}
});
这是一个具有类似实现的沙箱 https://codesandbox.io/s/muddy-smoke-5gwf0
推荐阅读
- c++ - boost::enable_if 在成员函数上,重载返回类型
- python - 组合多个数据框列
- makefile - patsubst 返回名称后展开变量
- angular - 使用角度路由参数而不订阅它
- umbraco7 - 在 Umbraco 7.6 中无法显示自定义部分
- c# - 我的 .Net Core 应用程序如何使用来自另一个应用程序的会话变量?
- flutter - Flutter TextField清除按钮位置错误
- apache-flink - 将 uid 添加到操作员会导致“无法映射操作员的检查点/保存点状态”
- android - Firebase 函数在 10 秒后在客户端提供超时
- javascript - 您如何定位和修改 Ionic/Angular 应用程序中的所有 CSS 元素实例?