sweetalert2:用作内容的预加载器

时间:2017-01-18 11:26:33

标签: sweetalert sweetalert2

我想用这种方式使用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窗口?

非常感谢!

!!! UPDATE:

这种方式对我有用:

$('.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
        });
    });

0 个答案:

没有答案