如何在ajax请求完成时关闭甜蜜警报

时间:2017-07-07 14:16:12

标签: javascript jquery angularjs ajax sweetalert

我在我的角应用中使用Sweet-alert

function GetDataFromServer(url) {
        SweetAlert.swal(
    {
        title: "",
        text: "Please wait.",
        imageUrl: "../../app/app-img/loading_spinner.gif",
        showConfirmButton: false
    });
        return $http.get(url)
        .then(success)
        .catch(exception);
        function success(response) {
            //SweetAlert.swal(
            //  {
            //      title: "",
            //      text: "data loaded",
            //  });
            return response.data;
        }
        function exception(ex) {
            return (ex);
        }

    }

Req#1(我这篇文章的主要目的)

  

我正在寻找的是ajax请求何时完成,即   控件进入then(),Sweet警报应自动隐藏。

要求#2 此外,在处理请求时,我不想在甜蜜警报中关闭“关闭”弹出按钮(“确定”按钮)。

enter image description here 根据文档,showConfirmButton: false应隐藏它,但不是。

任何帮助/建议都非常感谢。
感谢。

7 个答案:

答案 0 :(得分:16)

为了在弹出结束时自动隐藏弹出窗口,您应该将初始弹出窗口设置为变量,以便以后可以访问它。也许:

function GetDataFromServer(url) {
    SweetAlert.swal({
        title: "",
        text: "Please wait.",
        imageUrl: "../../app/app-img/loading_spinner.gif",
        showConfirmButton: false
    });
    return $http.get(url)
    .then(success)
    .catch(exception);
    function success(response) {
        swal.close()
        return response.data;
    }
    function exception(ex) {
        return (ex);
    }

}

它位于靠近底部的方法部分的https://t4t5.github.io/sweetalert/上。

因为你没有特定的方式'你想要隐藏确定按钮而你只是寻找建议,你总是可以使用一点CSS来定位它并给它{ol display: none;设置。

答案 1 :(得分:14)

您可以在任何需要的地方使用下面的代码行来关闭显示甜味剂的电流。

swal.close();

就是这样!

答案 2 :(得分:4)

如果您查看http://t4t5.github.io/sweetalert/

上的文档,SweetAlert的方法非常接近

您可以使用SweetAlert.close()以角度关闭sweetalert。

答案 3 :(得分:4)

您可以在甜蜜对象上使用close方法,请参阅下面的文档

https://t4t5.github.io/sweetalert/

swal.close(); - >以编程方式关闭当前打开的SweetAlert。

self.showProgress = function(message) {
  swal({ title: message });
  swal.showLoading();
};

self.hideProgress = function() {
  swal.close();
};

答案 4 :(得分:2)

如果您使用的是称为angular-sweetalert的AngularJS库,请使用swal.close();。关闭警报窗口。 angular-sweetalert是核心sweetalert库包的包装。

答案 5 :(得分:0)

browser.find_element_by_xpath('//span[@gogo-test="backers"]')不适用于swal函数(例如sync),您需要异步进行get调用

get

答案 6 :(得分:0)

缓存 swal() 以便稍后触发。

function GetDataFromServer(url) {

let swalAlert = SweetAlert.swal; // cache your swal

swalAlert({
    title: "",
    text: "Please wait.",
    imageUrl: "../../app/app-img/loading_spinner.gif",
    showConfirmButton: false
});
return $http.get(url)
.then(success)
.catch(exception);
    function success(response) {
        swalAlert.close(); // this is what actually allows the close() to work
        return response.data;
    }
    function exception(ex) {
        return (ex);
    }

}