我已经尝试过在JavaScript中2重的方向,在window.location.href()
和header()
但总是告诉我一个错误:的Javascript:头没有被定义
echo "<script> header('location: index.php');</script>";
我已经尝试过在JavaScript中2重的方向,在window.location.href()
和header()
但总是告诉我一个错误:的Javascript:头没有被定义
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;
错误使用代码。谢谢。我忘了那个header()是用于php的。 –
如果我不考虑退出,那该怎么办? –
不,因为如果你在'header()'下面有代码,它仍然会执行。 –
:
ReferenceError: header is not defined
我从PHP代码你不需要使用jquery 试试这个
echo header('Location: index.php');
exit;
您可以轻松地用下面的代码实现:
对于JavaScript在PHP中:
echo '<script>window.location.href="YOURURL.COM"</script>';
简易PHP:
echo header('Location: '."YOURURL.COM");
header()
是一个php函数。并且必须在发送任何实际输出之前调用header()
,可以使用普通HTML标记,文件中的空行或PHP。
<?php
header("Location: index.php"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
裁判:http://php.net/manual/en/function.header.php
在JS尝试,window.location.href = "index.php"
//的redirectUrl
'头()'是一个PHP函数,这就是为什么它在JavaScript不确定。只是'header('location:index.php');退出;'是必需的。不要“回声”它。 – Rasclatt