在 sweetalert Ok 弹出窗口后刷新当前页面

Refresh Current Page after sweetalert Ok Popup

我想在甜蜜提醒后刷新当前页面

下面是我的 C# 代码中的 javascript 代码 在此处输入代码

  url = HttpContext.Current.Request.Url.AbsoluteUri;
  ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", "alert('Please enter the correct data');window.location='" + url + "';", true); 

问题

 url = HttpContext.Current.Request.Url.AbsoluteUri;
 ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", "swal('success','Please enter the correct data','success');window.location='" + url + "';", true); 

页面正在刷新,但错过了温馨提示 请建议提前致谢

您似乎遗漏了 alert() 和 swal() 之间的主要区别:

function foo(){    
  alert("Hi");
  console.log("Hi");
}

弹出警报时,除非您确认消息,否则不会执行下一条语句。

function foo(){    
      swal("Hi");
      console.log("Hi");
    }

无论用户是否确认,都会执行日志语句。

因此适合您的代码段是:

swal('success','Please enter the correct data','success').then((value) => {
  window.location=url
})

虽然对于一些旧版本你可能必须这样做

swal({
  title: "Good job!",
  text: "You clicked the button!",
  icon: "success"
}, function(value){
    window.location=url;
});

您可以在此处找到文档:https://sweetalert.js.org/guides/#advanced-examples

单击“确定”按钮后问题已解决 Jquery 在客户端实现

   $(document).ready(function () {
        $(".swal-button").click(function () {
            //location.reload(); 
            window.location = 'Profile.aspx';
        });
    }); 

试试这个。它可能会帮助你。

 url = HttpContext.Current.Request.Url.AbsoluteUri;
 ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", "swal('success','Please enter the correct data','success');window.location.href='" + url + "';", true);