我已经尝试了 JavaScript 中的 2 个重定向,即 window.location.href()
和 header()
,但总是显示错误:
ReferenceError: header is not defined
我的 PHP 代码:
echo "<script> header('location: index.php');</script>";
最佳答案
JavaScript 中没有 header()
函数。 header()
是一个 PHP 函数。这是使用 JS 进行重定向的一种方法:
echo "<script> window.location.href = 'index.php'; </script>";
或者在 PHP 中:
header('Location: index.php');
exit;
关于Javascript: header 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39824591/