无法刷新HTML页面

问题描述:

我遇到问题。我用jQuery,jQuery-ui,jQuery mobile和kineticjs创建了一个HTML和PHP页面。切换到其他页面时,请勿刷新整个页面。我也尝试使用<meta http-equiv="refresh" content="URL=aa.php">,但没有奏效。 在该页面中,我也使用PHP从PHP获取结果。这里是我的PHP页面的代码:无法刷新HTML页面

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

+0

看起来你有jQuery两次。删除第二个参考。 – 2013-04-08 08:52:18

+0

我已经擦除了div后的jQuery ..结果是一样的..不工作.. – della 2013-04-08 08:58:38

+0

而不是插入整个源尝试减少代码到最小,仍然产生问题。 – vbence 2013-04-08 09:07:37

元刷新工作得这么:

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

但它不能。我不怎么这样。为什么..如果我使用你说的话,手动刷新我的页面后,它总是每秒刷新一次。 – della 2013-04-08 08:56:00

你可以使用它没有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错误。

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

document.location.reload(); 

或更改您的位置,如果你想:

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

试试这个,

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