简体   繁体   English

在PHP中执行一些Java脚本后如何重定向用户

[英]How to redirect user after performing some java script in php

I use php, html and sweetalert2 java script functions to show some notifications to the user. 我使用php,html和sweetalert2 Java脚本函数向用户显示一些通知。 I need show an alert after redirecting the user to the same (targeted) page. 将用户重定向到相同(目标)页面后,我需要显示警报。 This is the code I have 这是我的代码

function delete_cat(){
        include("include/db.php");
        include("include/notification.php");

        $delete_cat_id = $_GET['delete_cat'];
        $delete_cat= $con->prepare("DELETE FROM main_cat WHERE cat_id='$delete_cat_id'");

        if($delete_cat->execute()){
            echo '<script type="text/javascript">
                deleteMainCatSuccess();
                </script>';
            echo "<script>window.open('index.php?viewall_cat','_self')</script>";
        }
        else{
            echo '<script type="text/javascript">
                deleteMainCatError();
                </script>';
        }
    } 

And this is the notification java script 这是通知Java脚本

<script type="text/javascript">
     function deleteMainCatSuccess(){
        swal({ 
              title: "Success",
              text: "Delete Main Category Success",
              type: "success", 
              timer: 3000
        },
             function(){
                //event to perform on click of ok button of sweetalert
        });
  }
</script>

This works, but the notification shows for less than 1 second, after redirect the page. 此方法有效,但是在重定向页面后,通知显示的时间少于1秒。 I need stay some time to show notification and then redirect user to my target page. 我需要花点时间显示通知,然后将用户重定向到我的目标页面。 I have included timer: 3000 in the options, but it doesn't seem to make a difference. 我在选项中包括了timer: 3000 ,但似乎没有什么不同。

What can I do to fix this? 我该怎么做才能解决此问题?

swal({ 
  title: "Success",
  text: "Delete Main Category Success",
  type: "success" 
},
function(){
  window.open('index.php?viewall_cat','_self');
});  

Like this? 像这样?

i Fixed it like that 我这样修复

<script type="text/javascript">
function deleteMainCatSuccess(){
    swal({ 
          title: "Success",
          text: "Delete Main Category Success",
          type: "success", 
          timer: 3000
        }).then(function(){
            window.location.href='index.php?viewall_cat';
    });
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM