Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    javascript function to run using setInterger

    My apologies if this is not formatted correctly as I am on my phone and not everything displays correctly.

    I am trying to write a class or function (not sure which is needed) that controls stats on my page. I currently have a working example but I need additional functionality and I'm not sure how to do it. Basically it needs to run every 6 seconds to update the stats(as they change constantly).

    I need the javascript to connect(using ajax) to a database and retrieve stats to initially store as global variables. Then, as stated, I need it to modify(simple math that I can do) these stats every 6 seconds.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Thanked 568 Times in 565 Posts
    just call your function that checks the database from within setInterval, something like


    you may need to call the function that displays your stats again once the new ones come in (most likely from a callback function, to give the page time to load the new stats... although if you are constantly reloading the stats maybe you can get away without this and just have a lag), depending on how your code is set up
    Last edited by xelawho; 08-21-2011 at 11:57 PM. Reason: forgot about callback, again


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts