woolyg Posted March 5, 2010 Share Posted March 5, 2010 Is it possible to call setInterval halfway down a page, or from an AJAX call? I have a page, and what I'd like to happen is that when someone clicks a link, a div opens up for them, showing current info (all good, works fine). What I'd like to do then is to use setInterval() to update the Div I've just opened, and refresh the data. Is this possible? When I use <body onLoad="setInterval('update_online_users()', '5000');" > ..that updates the div fine, but I don't want it to be updating the div when the page loads, only when the AJAX call is made to populate the div in the first instance. At the end of my AJAX call I use <script type="text/javascript"> setInterval('update_online_users()', '5000'); </script> ..but it doesn't work. Can anyone shed any light on whether I'm barking up the right tree? WoolyG Quote Link to comment Share on other sites More sharing options...
trq Posted March 5, 2010 Share Posted March 5, 2010 You could try placing it within a self executing function. <script type="text/javascript"> (function() { setInterval('update_online_users()', '5000'); }()); </script> Quote Link to comment Share on other sites More sharing options...
woolyg Posted March 5, 2010 Author Share Posted March 5, 2010 Hmm, no joy. I placed the setInterval() into the OnClick of the link, and it sets the JS off, so I'm happy with that. Now, off to open a new post about trying to get rid of the dreaded AJAX flicker! Thanks! Quote Link to comment Share on other sites More sharing options...
TigerLV Posted March 5, 2010 Share Posted March 5, 2010 Could you post more of your code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.