【问题标题】:Refresh a PHP required file within a specific intervals在特定时间间隔内刷新 PHP 所需文件
【发布时间】:2018-02-26 21:14:13
【问题描述】:

我试过这些:

    <div id="result">
<table>
<?php require('newses.php'); ?>
</table>
</div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
   <script>
 function autoRefresh_div()
 {
      $("#result").load("load.html");// a function which will load data from other file after x seconds
  }

  setInterval('autoRefresh_div()', 1000); // refresh div after 5 secs
            </script>    

但这对我不起作用。 请访问这些页面:

Reload the content of a div afer regular interval of time

http://devzone.co.in/automatically-refresh-html-page-div-specific-time-interval/

【问题讨论】:

  • 您的刷新超时是 1 分钟而不是 5 秒。
  • 检查控制台有什么错误。在我这边它正在重新加载
  • @Sand如何设置1秒?
  • @Abhishek 真的有用吗?我真的可以使用客户端脚本重新加载服务器端脚本吗?
  • 而不是加载 load.html ,我正在做这种方法并且它的工作正常 "window.location.href =localhost/PhpProject1/chek.php" window.location.reload 刷新浏览器客户端但从服务器获取数据

标签: javascript php html reload ajax-polling


【解决方案1】:

我自己找到了答案。 我的代码中有一个小问题。 我希望我的页面在我的页面中包含 newses.php 文件,并在每 1 秒后刷新同一个文件 (newses.php)。 JavaScript 代码有一个小问题。刷新页面的代码名为 load.html,因此浏览器会在第一个网页加载 1 秒后尝试加载 load.html 页面。 当我将刷新代码从 $("#result").load("load.html");// a function which will load data from other file after x seconds 更改为 $("#result").load("newses.php");// a function which will load data from other file after x seconds 时,我的页面变得完全正常工作。 这是修改后的代码。

function autoRefresh_div() { $("#result").load("newses.php");// x 秒后从其他文件加载数据的函数 } setInterval('autoRefresh_div()', 1000) ; // 5 秒后刷新 div

【讨论】:

    【解决方案2】:

    function autoRefresh_div() {
      $("#result").html('<object data="https://static.pexels.com/photos/17679/pexels-photo.jpg"/>'); // a function which will load data from other file after x seconds
      alert('working');
    }
    
    setInterval(autoRefresh_div, 5000); // refresh div after 5 sec
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="result"></div>

    这将加载页面 5。

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 2021-09-02
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2020-08-18
      相关资源
      最近更新 更多