【问题标题】:Sweet alert not working properly甜蜜警报无法正常工作
【发布时间】:2018-04-29 05:43:24
【问题描述】:

我正在使用 sweetalert 在 ajax 响应成功但无法正确显示时显示一条消息,即没有显示成功图标。

这是我的 ajax 代码

var formData = $("#enqform").serialize();
      jQuery.ajax({
          type: 'POST',
          url: '<?php echo base_url() ?>tour-package/send-mail',
          data: formData,
          dataType: 'json',
          success: function(data){
            if(data.status == 1){
                swal({
                      title: "Thankyou!",
                      text: "Our excecutives will contact you soon.",
                      icon: "success",
                    });
                window.setTimeout(function() {
                    window.location.href = '<?php echo base_url() ?>tour-packages';
                }, 100000);
            }
            else{
                swal("Error occured !");
            }
          }
      }); 
      return false;
      e.preventDefault();
  }

https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.19.2/sweetalert2.min.css

https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.19.2/sweetalert2.min.js

我正在使用这些 css 和 js 来访问 sweetalert。

【问题讨论】:

  • 你有 icon: "success",但我在 SweetAlert 的文档中没有看到 icon 属性。也许你的意思是type: "success"
  • 对不起,我是第一次使用,请您说清楚。
  • icon: "success",更改为type: "success",

标签: jquery ajax sweetalert2


【解决方案1】:

更改图标类型对我有用

swal({
  title: "Thankyou!",
  text: "Our excecutives will contact you soon.",
  type: "success",
});

【讨论】:

    【解决方案2】:

    试试这个:

    var formData = $("#enqform").serialize();
          $.ajax({
              type: 'POST',
              url: '<?php echo base_url('tour-package/send-mail') ?>',
              data: formData,
              dataType: 'json'
    
              ).done(function(data)
              {
                if(data.status == 1){
                    swal({
                          title: "Thankyou!",
                          text: "Our excecutives will contact you soon.",
                          icon: "success",
                        });
                    window.setTimeout(function() {
                        window.location.href = '<?php echo base_url('tour-packages')?>';
                    }, 100000);
                }
                else{
                    swal("Error occured !");
                }
              });
           });

    【讨论】:

    • 在这种情况下,他需要将 'icon' 更改为 'type' 参数。
    • 为什么 swal2 的文档只显示不起作用的“图标”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2021-08-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多