Jump to content

Updating Page Without Reloading


DanH42
 Share

Recommended Posts

I've got a text document that contains a single line of text, which changes periodically. Is there a way to have a page display the contents of this file, then when it changes, display the new version under the new version, so you can see a history of changes?

Link to comment
Share on other sites

the only way i can think of is to have a JS function thats run over a short time period (maybe every minute). if the contents of the text document are different, then get the contents and display them on your page. Or just have a button on your page to trigger this JS function that would check for the contents, determine if its the same, and display the new results.

Link to comment
Share on other sites

The code I've worked out so far is:

<script> function update(){  document.getElementById('text').src = 'chat.txt?_dc=' + (new Date).valueOf();}setInterval(update, 5000);</script> <iframe id="text" src ="chat.txt" width="100%" height="40"></iframe>

This mostly works, but I want the updated text to appear under the old text rather than replacing it.

Edited by DanH42
Link to comment
Share on other sites

I looked through it, but JavaScript isn't really one of my stronger points. I'm kind of lost.
I'm pretty sure he meant the AJAX tutorial.
Link to comment
Share on other sites

AJAX (or more technically, the XMLHttpRequest object) is a component of JavaScript.The example is a almost what you need, but instead of replacing the element's text, you would want to concatenate on to it, e.g.

document.getElementById('test').innerHTML+="<br>" + xmlhttp.responseText;

You could also periodically check for changes using setTimeout() and only update if the contents has changed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...