hi all, i am trying to have the content of a txt file loaded in a page (which works), but this file changes on a regular basis and I need just the text to refreash, not the whole page, this is what I have... As mentioned, it correctly displayes the content of the .txt file, but from the code I have, I need it to refresh, any help would be greatly appreciated. Thank you in advance.

P.S. Only seems to work in IE at the moment, any advice on how to get it to work in FF would be greatly appreciated (in FF it just doesnt display the ocntent of the .txt file) Thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<style type="text/css">
.style1 {
	font-size: 1px;
	color: #e0e0e0;
.style2 {
	font-size: 10px;
	color: #e0e0e0;
.style3 {
	font-size: 9px;
	color: #000000;
<script language="javascript">
function GetSong(){
var url = "CurrentSong.txt";
var xmlhttp=new ActiveXObject("microsoft.xmlhttp");
try {
xmlhttp.open("GET", url, false);
var data=xmlhttp.responsetext;
} catch (e2) {
<script language="javascript">
function reloadIt()

  <table width="598" border="0" cellspacing="0" cellpadding="0">
      <td width="468"><div id="title">Now Playing:</div><div id="current"></div><script language="JavaScript">reloadIt();</script> 

<br /></td>
      <td width="120" rowspan="2">
<script type="text/javascript">

Recommended Answers

All 4 Replies

hi omega, some suggestions:
- use the XMLHttpRequest object instead of the ActiveXObject. The ActiveXObject is only supported by IE while the XMLHttpRequest object is cross-browser
- if you want to call the GetSong method periodically, you can use the setInterval method instead of the setTimeout method
- call the setInterval method when the page has been loaded.

Here is an example how to implement:

	<script type="text/javascript">	
		function GetSong () {
			var url = "CurrentSong.txt";
			var xmlhttp = new XMLHttpRequest;
			xmlhttp.open ("GET", url, false);    // synchron
			xmlhttp.send (null);

			var data = xmlhttp.responsetext;

		function Init () {
			GetSong ();
			setInterval (GetSong, 10000);
<body onload="Init ()">


the third parameter of the open method specifies whether the request needs to be handled asynchronously or not.
If it is true, the send method returns immediately. In that case, use the onreadystatechange event to be notified about the states of the request.
If it is false, the send method does not return, while the operation is in progress. Do not use this value if you do not want to keep the user waiting.

For further details and examples, see the following pages:

onload event,
open method,
XMLHttpRequest object,
setInterval method,

thanks i'll try this

hi, thank you very much for replying, and my apologies for lack of understanding, but i have no idea how to implement this, how do i call it? thank you for your patience

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.