【问题标题】:Sweetalert closes popup on confirm to call api requestSweetalert 在确认调用 api 请求时关闭弹出窗口
【发布时间】:2019-04-08 10:40:11
【问题描述】:

点击确认后我的弹出窗口关闭并再次打开一个显示成功的新弹出窗口。没有显示加载过程的地方有一个巨大的差距。

我已阅读 sweetalert 上的 ajax 请求文档。它在那里工作得非常完美,按钮在调用 API 时显示加载。我正在尝试做同样的事情。我想删除我第一次打开 swal 以确认的请求,如果是,它将调用 api 而不会关闭弹出窗口。

removeSession: function(sessionId){
    var _this = this;
    var errormessage = 'Error! Session not delete';
    var callData = {}
    callData["sessionId"] = 0;
    swal({
        title: "Are you sure?",
        text: "Once deleted, the session will be removed.",
        icon: "warning",
        buttons: true,
        dangerMode: true,
      })
      .then((willDelete) => {
        if (willDelete) {
            app.apiCustomPost(apiController_data, "delete", callData , function(res){

                if(res.status=="success") {

                    swal(res.message, {
                        icon: "success",
                      });
                      _this.init();

                } else {

                    swal(errormessage, {
                        icon: "error"
                    });                     

                }
            }); 
        } else {
            swal(errormessage, {
                icon: "error"
            });             
        }
      });
},

请帮助我更正我的代码。

【问题讨论】:

    标签: javascript jquery sweetalert


    【解决方案1】:

    我终于解决了这个问题。 buttonsweet alert 的属性有魔力。我们需要将 closeModal 值描述为 true 或 false 以关闭或不关闭模式。

    现在按钮在加载时显示...

    希望这对某人有所帮助。

    removeSession: function(sessionId){
        var _this = this;
        var errormessage = 'Error! Session not delete';
        var callData = {}
        callData["sessionId"] = 0;
        swal({
            title: "Are you sure?",
            text: "Once deleted, the session will be removed.",
            icon: "warning",
            buttons: {
    
                  cancel: {
                    text: "Cancel",
                    value: false,
                    visible: true,
                    className: "",
                    closeModal: true,
                  },
                  confirm: {
                    text: "OK",
                    value: true,
                    visible: true,
                    className: "",
                    closeModal: false
                  }
    
            },
            dangerMode: true,
          })
          .then((isConfirm) => {
            if (!isConfirm){ return false;}
    
    
                app.apiCustomPost(apiController_data, "delete", callData , function(res){
    
                    if(res.status=="success") {
    
                            swal(res.message, {
                                icon: "success",
                              });
    
                              _this.init();
    
                    } else {
                            swal(errormessage, {
                                icon: "error"
                            });                     
    
                    }
                }); 
    
          });
    
    },
    

    【讨论】:

    • 它对我不起作用!!通过使用按钮,它只显示一个默认按钮。
    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    相关资源
    最近更新 更多