Jquery:等待toastr通知结束然后重新加载

Gam*_*mer 1 javascript jquery toastr

由于模态形式,我使用 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();
});
Run Code Online (Sandbox Code Playgroud)

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

deb*_*ker 5

伟大的 toastr 已经有一个隐藏动画结束的回调:

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();
};
Run Code Online (Sandbox Code Playgroud)

编辑:

你也可以只覆盖一个 toast:

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