遇到一个很奇怪的页面跳转问题,看起来没什么问题却解了好久没解开,问了很多人也没解开。。。

我写了html、php两个文件,在html的form通过action跳转到php,再在php通过setTimeout(XXX,3000)回到html,但是从html提交表单到php,过了三秒跳回html的瞬间又跳回了php,然后再过三秒跳回html的瞬间再次跳回php,如此循环。。。。原本并没有这个问题的,突然之间不知道哪里出错了,就变成这种死循环的情况。希望有大佬路过能拯救萌新!下面是代码:

首先是FirstPage.html文件里的表单:

<form action="Sign.php" method="post">
                <table border="0">
                    <tr>
                        <td>名字:</td>
                        <td><input type="text" name="name"/></td>
                    </tr>
                    <tr>
                        <td>邮箱:</td>
                        <td><input type="text" name="email" /></td>
                    </tr>
                    <tr>
                        <td>密码:</td>
                        <td><input type="text" name="password"/></td>
                    </tr>
                        <tr>
                        <td>确认密码:</td>
                        <td><input type="text" name="rePassword"/></td>
                    </tr>
                </table>
                <input id="Submit" type="submit" value="提交" />
            </form>

接着是Sign.php的情况(只截了片段,无代码错误):

<script type="text/javascript">
            $(function () {
                var s = 3;
                setTimeout(function () {
                    window.location.href = "FirstPage.html";
                },3000);
                setInterval(function () {
                    s--;
                    $('span').html(s);
                },1000)

            })
        </script>
    </head>
    <body>
        <div><span>3</span>秒后将自动跳转</div>
    </body>
    </html>

会不会是你本地浏览器缓存问题? 建议上传段视频复现一下你的问题。

提交按钮改成div试试

<form id="loginForm" action="Sign.php" method="post">
                <table border="0">
                    <tr>
                        <td>名字:</td>
                        <td><input type="text" name="name"/></td>
                    </tr>
                    <tr>
                        <td>邮箱:</td>
                        <td><input type="text" name="email" /></td>
                    </tr>
                    <tr>
                        <td>密码:</td>
                        <td><input type="text" name="password"/></td>
                    </tr>
                        <tr>
                        <td>确认密码:</td>
                        <td><input type="text" name="rePassword"/></td>
                    </tr>
                </table>
                <div onclick="document.getElementById('loginForm').submit();" >提交</div>
            </form>

你要检查一下你的提交按钮是否还有其他方法在调用。。