【问题标题】:Can't refresh HTML page无法刷新 HTML 页面
【发布时间】:2013-04-08 08:48:55
【问题描述】:

我有问题。我用 jQuery、jQuery-ui、jQuery mobile 和 kineticjs 制作了一个 HTML 和 PHP 页面。切换到另一个页面时,不要刷新整个页面。我也尝试过使用<meta http-equiv="refresh" content="URL=aa.php">,但没有奏效。 在该页面中,我还使用 php 从该 PHP 中获取结果。这是我的 php 页面中的代码:

<?php
    if ( isset($_POST['address']) && isset($_POST['prefix']) && isset($_POST['levels']) ) {
        require_once 'convert.php';
        $network = new Network($ip, $prefix, $levels);
        print_html($network);
        exit();
    }
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="refresh" content="URL=aa.php">
        <title>aa</title>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <link rel="stylesheet" href="css/jquery.mobile-1.3.0.css" />
        <script src="js/jquery-1.9.1.js"></script>
        <script src="js/jquery.mobile-1.3.0.js"></script>
        <script src="js/jquery-ui.js"></script>
        <script src="js/kinetic-v4.3.2-beta.js"></script>
    </head>
    <body>
        <div data-role="page">
            <div data-role="header">
                <h3>aa</h3>
            </div>
            <div data-role="content">
                <h3>aa</h3>
                <br />
                <div>
                    <label for="address">Address:</label>
                    <input type="text" id="address">
                    <select id="prefix">
                        <?php for ( $i = 49; $i < 64; $i++ ) : ?>
                        <option value="<?php echo $i; ?>">/<?php echo $i; ?></option>
                        <?php endfor; ?>
                    </select>
                    <label for="subnet">Total Subnets: </label>
                    <input type="text" id="subnets">
                    <button class="btn" id="build"> Build It </button>
                </div>

                <div id="network"></div>
            </div>
        </div>

        <script src="js/jquery.js"></script>    
        <script type="text/javascript">
            $(function(){
                $("#build").click(function(){
                    var subnets = parseInt( $("#subnets").val() );
                    var address = $("#address").val();
                    var prefix = $("#prefix").val();
                    var levels = $("#subnets").val();
                    $.post("aa.php", {address:address, prefix:prefix, levels:levels}, function(response){
                        $("#network").html(response);
                        $("#network > .branch").show();
                        $("#network .open-children").click(function(){
                            $(this).text('-');
                            $(this).parent().children(".branch").toggle();
                            return false;
                        });
                    });
                });
            });
        </script>
    </body>
</html>

问题是否来自过多的javascript?

【问题讨论】:

  • 看起来你包含了 jQuery 两次。删除第二个引用。
  • 我已经在 div 之后删除了 jQuery..结果是一样的..不工作..
  • 不要插入整个源代码,而是尝试将代码减少到仍然会产生问题的最低限度。

标签: php jquery html jquery-ui jquery-mobile


【解决方案1】:

元刷新应该这样工作:

<meta http-equiv="refresh" content="0;url=aa.php">

【讨论】:

  • 但它不能......我不知道为什么......如果我使用你所说的,在我手动刷新我的页面后它总是每秒刷新......
【解决方案2】:

不用JS也可以使用。

<noscript><meta http-equiv="refresh" content="0;URL='?nojs=1'"></noscript>

检查控制台中是否有任何错误并将其删除。此外,您应该检测您是否拥有移动版或 PC 版浏览器,并包括 jquery-1.9.1.js 或 jquery.mobile-1.3.0.js

你也可以使用

window.location

使用 setInterval 或 setTimeout 它会做同样的事情。但是你不能有任何 JS 错误。

【讨论】:

    【解决方案3】:

    您可以使用此 javascript 代码刷新您的页面:

    document.location.reload();
    

    或根据需要更改您的位置:

    document.location = "http://google.com";
    

    【讨论】:

      【解决方案4】:

      试试这个,

      <meta http-equiv="refresh" content="0;url=aa.php">
      

      【讨论】:

        猜你喜欢
        • 2013-12-14
        • 2013-03-22
        • 2012-05-23
        • 2015-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-27
        相关资源
        最近更新 更多