使用 sweetalert 加载进度表提交

loading progress form submit using sweetalert

我想在提交表单时呈现等待时间动画,但我更喜欢使用 SweetAlert 而不是标准加载图像。

这是基本代码:

$("form").submit(function (e) {
            e.preventDefault(); // stops the default action
            $("#loader").show(); // shows the loading screen
            $.ajax({
                url: test.php,
                type: "POST"
                success: function (returnhtml) {
                    $("#loader").hide(); // hides loading sccreen in success call back
                }
            });
        });

这是 SweetAlert 想要实现的代码:

window.swal({
  title: "Checking...",
  text: "Please wait",
  imageUrl: "images/ajaxloader.gif",
  showConfirmButton: false,
  allowOutsideClick: false
});

//using setTimeout to simulate ajax request
setTimeout(() => {
  window.swal({
    title: "Finished!",
    showConfirmButton: false,
    timer: 1000
  });
}, 2000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" />

请有人提出这样做​​的提示

你快到了!只需将 #loader 代码替换为甜蜜警报代码即可。

$("form").submit(function (e) {
            e.preventDefault(); // stops the default action
            //$("#loader").show(); // shows the loading screen
            window.swal({
              title: "Checking...",
              text: "Please wait",
              imageUrl: "images/ajaxloader.gif",
              showConfirmButton: false,
              allowOutsideClick: false
            });
            $.ajax({
                url: test.php,
                type: "POST"
                success: function (returnhtml) {
                    //$("#loader").hide(); // hides loading sccreen in success call back
                    window.swal({
                      title: "Finished!",
                      showConfirmButton: false,
                      timer: 1000
                    });
                }
            });
        });