duancenxie2233 2015-08-31 15:35
浏览 16
已采纳

重复网站中包含的PHP脚本

I've searched all around for a solution to my problem, but I can't seem to understand where to put the solution.

I'm creating a webpage which will show information from different API sources, and I would like all the information to be updated on different intervals.

I've seen the "while(true) { sleep(5); }" solution, but it just freezes the website, preventing it to load.

Lets say my webpage looks like this:

<body>
<?php

echo "hello world";

?>
</body>

How can I make the php script repeat on certain intervals?

Thank you.

  • 写回答

1条回答 默认 最新

  • douyu2817 2015-08-31 16:09
    关注

    The question you have is basically about the use of client side and server side scripting. A language like php runs on the server and not on the computer of the client, the user. Therefore, it cannot change anything on the webpage as soon as it has been sent off to the user. That is where client-side scripts come in play.

    The server can send a script in a language like javascript to the user if a link to the script is included in the html. Those scripts will be executed on the user's browser. With an combination of Javascript and AJAX (stands for Asynchronous JavaScript and XML, and is not a language btw), you can load a php-file into your page. You can use javascript to let AJAX do that every x miliseconds with the function setInterval()

    A few links and tutorials:

    http://www.w3schools.com/ajax/

    http://www.w3schools.com/jsref/met_win_setinterval.asp

    http://www.w3schools.com/js/default.asp

    http://www.tutorialspoint.com/ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错