Jump to content

Dynamically reading and displaying values


seth001

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.