dongyou8701 2010-08-13 20:59
浏览 66
已采纳

寻找一个好的JQuery计数器[关闭]

I have a website that has members. I want to create a feature that is a real time (with out page load ) counter of how many members are signed in. I have the signed in user in a variable so I'm looking for someway to incorporate it using that. Anyone know of a good plug-in or Jquery script to do this?

thanks in advance

  • 写回答

2条回答 默认 最新

  • dongzhiyan5693 2010-08-13 21:04
    关注

    You really don't need a plugin so much, just create a page that does nothing but echo the count then call that page on an interval, for example:

    function updateCount() {
      $('#userCount').load('myCounter.php', function() {
         setTimeout(updateCount, 2000);
      });
    }
    $(updateCount); //run on document.ready
    

    This uses .load() to fetch the count and place it in the #userCount element (a <span> or <div>, whatever it is), wait 2 seconds and do it again. You want to avoid setInterval() in these cases because the ajax request time is an unknown, and you don't want those to start overlapping. Instead, use setTimeout() so it runs again 2 seconds (or however often you want) after the request completes.

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

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏