Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用javascript警报后未执行php代码_Javascript_Php_Redirect - Fatal编程技术网

调用javascript警报后未执行php代码

调用javascript警报后未执行php代码,javascript,php,redirect,Javascript,Php,Redirect,我在调用javascript警报后执行php重定向时遇到了一些问题。代码如下: echo '<script>window.alert("This device is aleady registered to another user");</script>'; header('Location: page.php'); echo'window.alert(“此设备已向其他用户注册”); 标题('Location:page.php'); 单击警报上的“确定”后,将不执行

我在调用javascript警报后执行php重定向时遇到了一些问题。代码如下:

echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');
echo'window.alert(“此设备已向其他用户注册”);
标题('Location:page.php');
单击警报上的“确定”后,将不执行重定向。关于如何让代码正常工作,有什么想法吗


谢谢

您不能在输出后发送标题。只需通过javascript一路重定向用户即可

echo '<script>window.location.href = "page.php";</script>';
echo'window.location.href=“page.php”;

在调用
标题之前,您不能输出任何内容,甚至不能输出一个空格。您可以在输出脚本之前使用header,如下面的代码所示

header('Location: page.php');
echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location:page.php');
echo“window.alert”(“此设备已向其他用户注册”);

希望这对您有所帮助

这是您可以使用的最好方法:-

窗口位置

试试这种方法

echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';
echo'窗口。警报(“此设备已向其他用户注册”);
window.location.href=“page.php”;
';

请检查我的答案