【问题标题】:Jquery : Wait for the toastr notification to end then reloadJquery:等待 toastr 通知结束然后重新加载
【发布时间】:2018-03-06 10:00:03
【问题描述】:

由于模态形式,我正在使用 ajax, 我有一个 toastr 通知显示 ajax 成功。

toastr.success("We will get back to you with response, Thanks !");

然后: window.location.reload();

我怎样才能让它先结束通知然后重新加载。 我发现了一些东西,但它很快重新加载了页面:

$.when( toastr.success("We will get back to you with response, Thanks !") ).then(function( data, textStatus, jqXHR ) {
    window.location.reload();
});

还有其他合适的/最佳实践方式吗?

【问题讨论】:

    标签: javascript jquery toastr


    【解决方案1】:

    大烤面包机已经有隐藏动画结束的回调了:

    toastr.options.timeOut = 1000;
    toastr.options.fadeOut = 1000;
    toastr.options.onHidden = function(){
      // this will be executed after fadeout, i.e. 2secs after notification has been show
      window.location.reload();
    };
    

    编辑:

    您也可以只覆盖一个 toast:

    toastr.success(
      'Have fun!',
      'Miracle Max Says',
      {
        timeOut: 1000,
        fadeOut: 1000,
        onHidden: function () {
            window.location.reload();
          }
      }
    );
    

    【讨论】:

    • 所以这是静态的,因为我们正在给它时间。对吧?
    • @Gammer:它已经全部内置,请参阅我的第二个示例 - 第三个参数用于选项覆盖。 THX
    猜你喜欢
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    相关资源
    最近更新 更多