admin管理员组文章数量:1410737
I already tried the 2 re-directions in JavaScript, the window.location.href()
and header()
but always show me an error:
ReferenceError: header is not defined
My code from PHP:
echo "<script> header('location: index.php');</script>";
I already tried the 2 re-directions in JavaScript, the window.location.href()
and header()
but always show me an error:
ReferenceError: header is not defined
My code from PHP:
echo "<script> header('location: index.php');</script>";
Share
Improve this question
edited Oct 3, 2016 at 5:21
Rax Weber
3,78020 silver badges30 bronze badges
asked Oct 3, 2016 at 4:24
Agel SalazarAgel Salazar
31 silver badge2 bronze badges
1
-
1
header()
is a php function, that is why it is undefined in JavaScript. Justheader('location: index.php'); exit;
is required. Don'techo
it though. – Rasclatt Commented Oct 3, 2016 at 4:27
4 Answers
Reset to default 5There's no header()
function in JavaScript. header()
is a PHP function. Here is one way to redirect using JS:
echo "<script> window.location.href = 'index.php'; </script>";
Or in PHP:
header('Location: index.php');
exit;
you dont need to use jquery try this
echo header('Location: index.php');
exit;
You can easily achieve with Below Code:
For JavaScript in PHP:
echo '<script>window.location.href="YOURURL.COM"</script>';
For Simple PHP:
echo header('Location: '."YOURURL.COM");
header()
is a php function. and header()
must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
<?php
header("Location: index.php"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
ref: http://php/manual/en/function.header.php
in js try, window.location.href = "index.php"
//redirectUrl
本文标签: phpJavascript header is not definedStack Overflow
版权声明:本文标题:php - Javascript: header is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744314944a2600214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论