douxiong2001 2017-07-31 10:51
浏览 29
已采纳

根据时间间隔检查变量更改(PHP + HTML)

so i am just wondering if i could do this:

a basic site, nothing on it but 4 different photos that have different priority levels which indicate the time-span of actually displaying an image ( lvl1=1min, lvl2=3min, lvl3=10min...and so on) How could i do this with html and php.. I am not sure if answer is really basic but i cant seem to get my head around it. Is html code running parallel to php code or does an infinite while loop in php stop the whole html code in process?

I was thinking of creating an infinite while loop in but i am worried it would eventualy somehow crash the site?

I guess i dont understand how html code runs..

Thanks to anyone who helps.

  • 写回答

4条回答 默认 最新

  • dt3358 2017-07-31 10:59
    关注

    For you purpose you can use AJAX which is update your code on given time interval. If you want to set something on a timer, you can use JavaScript's setTimeout or setInterval methods:

    setTimeout ( expression, timeout );
    setInterval ( expression, interval );
    

    Here expression is a normal function and timeout and interval are integers in milliseconds. setTimeout runs the timer once and runs the expression once whereas setInterval will run the expression every time the interval passes.

    So in your case it would work something like this:

    setInterval(function() {
        //call $.ajax here
    }, 5000); //5 seconds
    

    As far as the Ajax goes, see jQuery's ajax() method. If you run an interval, there is nothing stopping you from calling the same ajax() from other places in your code.

    Anymore expression need please let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效