Jump to content

Updating Page Without Reloading


DanH42

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...