douyiyi5284 2014-01-25 12:27
浏览 51
已采纳

PHP倒计时计时器操作

Hi all apologies if this is an easy solution, I am creating an test application and require that a timer is started when the user clicks on the test. I am however completely confused how to implement a counter for the application - and how to trigger an action when the timer has reached 0.

I have found implementations of JS timers/countdowns:

PHP Timer wait 30 seconds then run a command

PHP when countdown runs out

and a php timer:

Start and stop a timer PHP

I was hoping that someone could help me with an example of a PHP timer that triggers an action when it has reached 0 for example - redirecting to another page.

Many thanks in advance - please have patience, I am a total beginner

  • 写回答

1条回答 默认 最新

  • doutao4938 2014-01-25 12:40
    关注

    Using JQuery:

    function runTimer(seconds, yourUrl) {
      setTimeout(function() {
        $.get(yourUrl);
      }, seconds * 1000;
    }
    

    run it:

    runTimer(5, 'http://example.com/action.php');
    

    But it won't be possible to redirect to other page using ajax request.

    For redirecting use:

    function runTimerRedirect(seconds, yourUrl) {
      setTimeout(function() {
        window.location = yourUrl
      }, seconds * 1000;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题