dtgsl60240 2018-12-06 13:57
浏览 159
已采纳

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

I'm trying to make this work but there something wrong:

<?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>

I tried this one [php on submit redirect to another page

But still doesn't work.

Thanks in advance for any help guys.

  • 写回答

1条回答 默认 最新

  • duanmu2015 2018-12-06 13:59
    关注

    It should be something like:

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

    //-----edit-----//

    You've actually nothing being posted as 'submit'.

    if(isset($_POST['menu_post'])){
        echo "<script>window.location.href='https://google.com'</script>";
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog