通知显示完全完成后重新加载页面

问题描述 投票:0回答:4

这里有人要如何修复我的通知吗?我想显示通知已完全完成,然后重新加载页面。目前,我的通知快速退出并且未完全显示。我在这方面使用了ajax和toastr。非常感谢你们!非常感谢您的帮助。这是我尝试过的:

function InsertOrUpdateExpense() {
    var data = $('#formExpenseTransaction').serialize();
    $.ajax({
        type : 'POST',
        url : url + 'InsertOrUpdateExpenseTransaction',
        data : data,
        dataType : 'json',
        beforeSend:function() {
            $('#btn-expense--transaction').html(' <i class="icon-spinner2 spinner"></i>').attr('disabled',true);
        },
        success:function(data) {
            data.success === true ? notify(data.type,data.message) : notify(data.type,data.message);
            var content = data.type == 'info' ? 'Save Changes' : 'Add Expense';
            $('#btn-expense--transaction').html(content +' <i class="icon-arrow-right14 position-right"></i>').attr('disabled',false);
            setTimeout(function() {
                location.reload();
            }, 3000);
        }
    });
}

function notify(type,message) {
    Command: toastr[type](message)
}

function toastr_option() {
    toastr.options = {
        "newestOnTop": true, "progressBar": false, "positionClass": "toast-top-right", "preventDuplicates": true, "showDuration": 300, "hideDuration": 1000, "timeOut": 5000, "extendedTimeOut": 1000, "showEasing": "swing", "hideEasing": "linear", "showMethod": "slideDown", "hideMethod": "slideUp"
    }
}
javascript jquery ajax toastr
4个回答
1
投票

只需将 location.reload() 从 setTimeout 内部移动到 toastr 的一个选项,名为“onHidden”。

function toastr_option() {
    toastr.options = {
        "newestOnTop": true, "progressBar": false, "positionClass": "toast-top-right", "preventDuplicates": true, "showDuration": 300, "hideDuration": 1000, "timeOut": 5000, "extendedTimeOut": 1000, "showEasing": "swing", "hideEasing": "linear", "showMethod": "slideDown", "hideMethod": "slideUp", onHidden: function(){. location.reload(); }
    }
}

1
投票

我不知道toastr,但是阅读他的文档你可以尝试使用他的回调函数。

在他的例子中:

toastr.options.onHidden = function() { console.log('goodbye'); }

类似这样的:

function toastr_option() {
    toastr.options = {
        "newestOnTop": true, "progressBar": false, "positionClass": "toast-top-right", "preventDuplicates": true, "showDuration": 300, "hideDuration": 1000, "timeOut": 5000, "extendedTimeOut": 1000, "showEasing": "swing", "hideEasing": "linear", "showMethod": "slideDown", "hideMethod": "slideUp"
    }
    toastr.options.onHidden = function() { location.reload(); }
}

0
投票

你可以这样做

toastr.success(
          'Done',
          'Added Successfully',
        {
          timeOut: 1000,
          fadeOut: 1000,
          onHidden: function () {
            window.location.reload();
         }
       });

0
投票

对于使用 toast 的 React 用户

toast.success(errorMessage,
{   
  onClose: () => {
    setTimeout(()=>{
      window.location.reload();
    },6000)
}
});

onclose 和 toast 通知将取决于超时时间。 (6000 是 6 秒)

© www.soinside.com 2019 - 2024. All rights reserved.