php jquery onclick提交重定向到另一个页面

php jquery onclick submit redirect to another page

我正在尝试完成这项工作,但出现了问题:

<?php
if(isset($_POST['submit'])){
    echo "<script>location='https://google.com'</script>";
exit();
}
?>

<html>
<head>

<script>
    function onSubmit() {
        document.getElementById('menu_post').value = 'main';
        document.forms['MenuForm'].submit();
    }

</script>

</head>
<body>

<a onclick="onSubmit();return false;" href="javascript:void(0)">Test</a>

<form name="MenuForm" method="post" action="index.php">
    <input type="hidden" id="menu_post" name="menu_post" value="" />
</form>

</body>
</html>

我试过这个[php on submit redirect to another page

但是还是不行。

在此先感谢您的帮助。

应该是这样的:

if(isset($_POST['submit'])){
    echo "<script>window.location.href='https://google.com'</script>";
    exit();
}

//-----编辑-----//

您实际上没有发布任何内容 'submit'。

if(isset($_POST['menu_post'])){
    echo "<script>window.location.href='https://google.com'</script>";
    exit();
}