SweetAlert2:配置警报的一些困难

问题描述 投票:0回答:1

我正在尝试使用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();
                            })
                        });
                    }
                });
javascript sweetalert confirm sweetalert2
1个回答
0
投票

如何做

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

© www.soinside.com 2019 - 2024. All rights reserved.