Sweetalert2重定向

时间:2017-11-16 12:56:50

标签: javascript php sweetalert sweetalert2

我已经挣扎了几个小时了,我认为解决方案非常简单。首先是一些背景知识。

所以,我有一个php页面,我可以在texfield中输入一个数字。如果输入的数字高于用户的信用,那么我必须显示错误消息。当用户点击按钮发送表单时,我去makeTransfer.php,我在这里做了几个检查。如果,正如我所说,用户没有足够的信誉,我想使用SweetAlert2向他显示一条错误消息,然后将他重定向到上一页(让我们称之为收银员)。此刻,我可以显示警报,但我无法重定向他:(。

以下是代码:

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

请帮忙吗?我只是想显示警告,一旦用户点击“接受”按钮,就会将他重定向到cashier.php

提前致谢!

4 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

swal({
  title: 'Redirect',
  text: "Message",
  type: 'success',
}).then(function (result) {
  if (true) {
    window.location = "cashier.php";
  }
})
像这样,如果if返回true,它将重定向到同一目录中的cahsier.php,你也可以将它留下来

答案 2 :(得分:0)

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

<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>

工作了我的**,但它得到了回报:)。谢谢所有试图帮助我的人。

答案 3 :(得分:0)

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

请相信我,上面的脚本对我有用!谢谢