微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 swal 在 ajax 后重新加载页面

如何解决使用 swal 在 ajax 后重新加载页面

我有一些这样的 swal 代码

  $('#config-reset').click(function(event) {
    event.preventDefault()
    swal({
      text: 'some text',dangerMode: true,showLoaderOnConfirm: true,buttons: true,})
    .then((result) => {
      if (result !== null) {
        return $.post("url")
      }
      return false
    })
    .then((result) => { 
      if (result.result.success == 'done') {
        swal({ text: "Done",icon: "success",}); 
      }
      else{
        swal(result.result.error); 
      }
    })
    .catch(err => { 
      swal(err.statusText); 
    });
  })
})

在 ajax 调用返回并且 Done/success swal 被清除后,我想重新加载页面。如果我在 swal 之后重新加载它会在 swal 被清除之前发生。如果我在第二个 .then 之后把它放在 .then 中也是一样。如何让重新加载在警报清除后才运行?

解决方法

请添加选项 services.AddAuthorization(o => { o.AddPolicy("AtLeastStore",policy => policy.Requirements.Add(new StoreOrGreaterRequirement())); o.FallbackPolicy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); });

onClose

如果您使用的是 sweetalert v1,请尝试这样:

swal({
    text: "Done",icon: "success",onClose: function(){
        location.reload()
    }
}); 

或者:

swal({
    text: "Done",icon: "success"
    confirmButtonText: "Ok",},function(isConfirm){
    if(isConfirm)location.reload()
}); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。