简体   繁体   English

每24小时了解一次php代码并调用javascript函数

[英]understanding php code and Call javascript function once in 24hours

I came accross following code: 我遇到以下代码:

<script type="text/javascript">
        var timeoutId;
        var intervalId;

        function doIt(){
            $("#main").load("refresh.php");
        }
        $(document).ready(function(){
            timeoutId = setTimeout(function(){
                doIt();
                intervalId = setInterval(function(){
                    doIt();
                }, 5000); //Request the doIt() method every 5ms.
            }, 3000); //Delay calculated on the server to trigger the function at the appropriate time
        }); 
    </script>  
  1. Rather then calling every 5 second is there any way to call it at 8am everyday in the morning? 而不是每隔5秒打电话一次,有没有办法每天早上8点拨打电话?

  2. $("#main").load("refresh.php"); will load the result from refresh.php page on div with id main right? 会从ID为main的div的refresh.php页面加载结果?

You'll have to keep the browser up all the time, because javascript is a client side language. 您必须一直保持浏览器运行,因为javascript是一种客户端语言。

Instead use Cron Job , to schedule tasks. 而是使用Cron Job来安排任务。

You don't need to call it every morning at 8 AM. 您不必每天早上8点打电话给它。

If the browser is open at 8 AM, just make a call to server to get the latest data. 如果浏览器在上午8点打开,则只需致电服务器即可获取最新数据。

You can use the getHours() method of date object and check the time. 您可以使用date对象的getHours()方法并检查时间。 At 8 AM, refresh the data. 在8 AM,刷新数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM