<html>
<head>
</head>
<body>
<h3>Stock Quote: <span id=quote>?</span></H3>

<script>
// stock ticker
// global variables.
q = document.getElementById('quote');
var x;

// This is the callback. When the readystate changes this function
// will be called.
function handleDoc() {
  if (x.readyState == 4) {
	// everything is good, the response is received
	if (x.status==200) {
	   // fetch was successful - we have a document.
	   doc = x.responseXML;
	   // find all price tags
	   list = doc.getElementsByTagName('price');
	   // we are only looking for one
	   elem = list.item(0);
	   // grab the first child (which is the content of the tag)
	   content = elem.firstChild;
	   // finally, grab the value (CDATA)
	   price = content.data;

	   // update the span in this document 
	   q.innerHTML=price;    
   
       // sechedule this to happen again in one second
       window.setTimeout("fetch()",1000);
    } 
  } else {
	// still not ready (ignore)
  }
}

// This function updates the stock price by
// initiating a new request for quote, and sets up
// handlDoc to get called with the answer arrives.
function fetch() {
     x = new XMLHttpRequest();
     x.onreadystatechange = handleDoc;
     x.open('GET', 'feed.php', true);
     x.send(null);
}

// call fetch to start the ball rolling
fetch();
</script>
</body>
</html>