我使用ajax因为模态形式, 我有一个关于ajax成功的toastr通知。
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();
});
还有其他合适/最佳实践方式吗?
答案 0 :(得分:2)
伟大的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();
};
编辑:
您也可以只覆盖一个吐司:
toastr.success(
'Have fun!',
'Miracle Max Says',
{
timeOut: 1000,
fadeOut: 1000,
onHidden: function () {
window.location.reload();
}
}
);