3

我想以这种方式使用 sweetalert2:

$('.preloaderContent').click(function(e) {
        e.preventDefault();
        swal({
            title: "Data collecting....",
            text: "Please Wait!",
            type: "info",
            showLoaderOnConfirm: true,
            preConfirm: function() {
                return new Promise(function(resolve) {
                    $.ajax({
                        type: "get",
                        url: '/reports/test',
                        success: function(response){
                            $('.page-content').html(response);
                        }
                    })
                });
            }
        });
    });

如何使用 'swal.clickConfirm()' 开始加载而不需要让用户点击 'OK' 按钮?

加载所有内容后如何关闭 swal 窗口?

非常感谢!

!!!更新:

这样它对我有用:

$('.preloadData').click(function(e) {
        e.preventDefault();

        swal({
            title: "Collecting data....",
            text: "Please wait just one moment",
            type: "info",
            showLoaderOnConfirm: true,
            onOpen: function(){
                swal.clickConfirm();
            },
            preConfirm: function() {
                return new Promise(function(resolve) {
                    $.ajax({
                        type: "get",
                        url: '/x/xx/',
                        success: function(response){
                            $('.page-content').html(response);
                            swal.closeModal();
                        }
                    })
                });
            },allowOutsideClick: false
        });
    });
4

0 回答 0