Sweetalert2 重定向

Sweetalert2 redirection

我已经为此苦苦挣扎了几个小时,我认为解决方案非常简单。首先介绍一下背景。

所以,我有一个 php 页面,我可以在其中在文本域中输入数字。如果输入的数字高于用户的信用额度,那么我必须显示一条错误消息。当用户单击按钮发送表单时,我转到 makeTransfer.php 并在此处进行多项检查。如果正如我所说,用户没有足够的信用,我想使用 SweetAlert2 向他显示一条错误消息,然后将他重定向到上一页(我们称之为收银员)。目前,我可以显示警报,但无法重定向他:(.

代码如下:

echo '<script type="text/javascript">';
echo 'setTimeout(function () { swal("WOW!","Message!","error");';
echo '});</script>';

有什么帮助吗?我只想显示警报,一旦用户点击接受按钮,就会将他重定向到 cashier.php

提前致谢!

swal({
  title: 'WOW',
  text: "Message",
  type: 'error',
}).then(function (result) {
  if (result.value) {
    window.location = "/cashier.php";
  }
})
swal({
  title: 'Redirect',
  text: "Message",
  type: 'success',
}).then(function (result) {
  if (true) {
    window.location = "cashier.php";
  }
})

像这样,如果 returns 为真,它将重定向到与现在相同的目录中的 cahsier.php,您也可以将其保留

好的,问题解决了。这是代码:

<script type="text/javascript">
    $(document).ready(function() {
swal({ 
  title: "Error",
   text: "wrong user or password",
    type: "error" 
  }).then(function() {
    // Redirect the user
    window.location.href = "cashier.php";
    })});
</script>

辛苦了,但得到了回报:)。感谢所有试图帮助我的人。

Swal.fire({
    type: 'error',
    title: 'Oops...',
    confirmButtonText: 'Shopping',
    text: 'There is no items on your cart.',
    footer: '',
    showCloseButton: true
})
.then(function (result) {
    if (result.value) {
        window.location = "Default.aspx";
    }
})

相信我上面的脚本适合我!谢谢