DanH42 Posted January 16, 2010 Share Posted January 16, 2010 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 More sharing options...
Synook Posted January 16, 2010 Share Posted January 16, 2010 Yep - it's done with AJAX. Link to comment Share on other sites More sharing options...
skaterdav85 Posted January 17, 2010 Share Posted January 17, 2010 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 More sharing options...
DanH42 Posted January 17, 2010 Author Share Posted January 17, 2010 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 More sharing options...
Synook Posted January 17, 2010 Share Posted January 17, 2010 It would be easier with AJAX - did you read the tutorial? Link to comment Share on other sites More sharing options...
DanH42 Posted January 17, 2010 Author Share Posted January 17, 2010 It would be easier with AJAX - did you read the tutorial?I looked through it, but JavaScript isn't really one of my stronger points. I'm kind of lost. Link to comment Share on other sites More sharing options...
skaterdav85 Posted January 17, 2010 Share Posted January 17, 2010 Have you seen this example? Looks just like what you want to do.http://w3schools.com/ajax/tryit.asp?filename=tryajax_first Link to comment Share on other sites More sharing options...
thescientist Posted January 17, 2010 Share Posted January 17, 2010 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 More sharing options...
Synook Posted January 17, 2010 Share Posted January 17, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.