Well, without looking closely at that code, my guess is that it is specific to the W3C school and needs modification to work on any other site, urls etc.
Rather than help anyone to fix it, I'm going to give you the real answer, which is:
FORGET ALL THAT AND USE PROTOTYPE.JS
It is the same thing, AJAX, only it is so much more the same thing.
It is like using PDO or wasting time writing your own db class to do the same thing. No need to go through all that
try {
}
catch {
to see which browser it is cos prototype does it for you: code I just this minute wrote to do the same sort of thing as the 30 lines on W3C
<script type="text/javascript">
window.onload = getSummary;
function getSummary() {
new Ajax.Updater('ajax_data', 'http://tracker.b-band.co.uk/php/summary.php');
}
</script>
Wonderfull stuff eh! Loads a table according to who the user is via session id set at login. Go to Tracker and click the Demo to see it working. Of course the php page it calls is the same one as it would be with XMLHttpRequester.
Best part is that you can use
// trap all ajax calls and render tables
Ajax.Responders.register({
onCreate: function(){
},
onComplete: function(){
sortables_init();
}
});
To call another js function after any/all requests - in my case it calls sorttable.js to render any tables sortable.