seth001 Posted October 4, 2010 Share Posted October 4, 2010 Let's say I have a script that updates the database every 5 minutes. Or fwrites to a text file at an interval. How do I say create a dynamic textbook or label that displays this information and automatically UPDATES on the page without the user clicking on REFRESH? Quote Link to comment https://forums.phpfreaks.com/topic/215132-dynamically-reading-and-displaying-values/ Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2010 Share Posted October 4, 2010 ajax calls php script at regular intervals and updates the page content without refresh. Quote Link to comment https://forums.phpfreaks.com/topic/215132-dynamically-reading-and-displaying-values/#findComment-1118914 Share on other sites More sharing options...
Adam Posted October 4, 2010 Share Posted October 4, 2010 You can use JavaScript: var updateInterval; window.onload = function() { updateInterval = setInterval(updateText, 60000) // once a minute } function updateText() { var txt = // method of getting text document.getElementById('updateMe').innerHTML = txt; } The element that will contain the text needs defining: <span id="updateMe">Update me...</span> Populate the initial text normally to prevent users with JS disabled missing out. You'll notice I haven't actually written the AJAX request; you're better off reading up on AJAX first and understanding what it is and how it works, before you start using it. However I've given you the basic structure for your code which should allow you do make a start... All you need to do is submit a HTTP request either to the flat file containing the text, or a PHP script that will return the text for you. There's a lot of online resources that should be able to help you with that part. Quote Link to comment https://forums.phpfreaks.com/topic/215132-dynamically-reading-and-displaying-values/#findComment-1118918 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.