最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery : Wait for the toastr notification to end then reload - Stack Overflow

programmeradmin0浏览0评论

I am using ajax because of the modal form, I have a toastr notification to show on the ajax success.

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

And then : window.location.reload();

How can i make it to end the notification first and then relaod. I found something but it quickly reloads the page :

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

Is there any other suitable/Best practice way ?

I am using ajax because of the modal form, I have a toastr notification to show on the ajax success.

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

And then : window.location.reload();

How can i make it to end the notification first and then relaod. I found something but it quickly reloads the page :

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

Is there any other suitable/Best practice way ?

Share Improve this question asked Mar 6, 2018 at 10:00 GammerGammer 5,62820 gold badges82 silver badges132 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The great toastr has already a callback for the end of the hiding animation:

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();
};

EDIT:

You can override also just one single toast:

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

评论列表(0)

  1. 暂无评论