Hi,
I'd like to learn more about AJAX and began reading the first chapters of the "Build Your Own AJAX Web Applications" book by sitepoint. I'm now on chapter 3 and i'm having trouble getting the code in this chapter to work. I'm guessing at least a few people here read this book and i'd appreciate it if someone could help me.. The problem starts at the "Polling the Server" section. I have added alerts in the code to help determine when the script stops working.

within the doPoll() function there is this following line:

self.ajax.doGet(self.targetURL + '?start=' + self.start,self.showPoll);

this is where the problem is.. the alert just before it pops up where as the second one does not.

The ajax.doGet function is fine because 've used it on chapter two without any issues.

I'm attaching the code of this chapter (up till the "Polling the Server" section). If anyone could point out where the problem is i'd be very grateful.

Code:
var Status = new function() {
 this.init = function() {
   // don't mind me, I'm just a stub ...
 };
 this.startProc = function() {
   // another stub function
 };
 this.stopProc = function() {
   // another stub function
 };
}

var Monitor = new function(){
	this.targetURL = null;
	this.pollInterval = null;
	this.maxPollEntries = null;
	this.timeoutThreshold = null;
	this.ajax - new Ajax();
	this.start = 0;
	this.pollArray = [];
	this.pollHand = null;
	this.timeoutHand = null;
	this.reqStatus = Status;


this.toggleButton = function(stopped){
var self = Monitor;
var buttonDiv = document.getElementById('buttonArea');
var but = document.createElement('input');
but.type = 'button';
but.className = 'inputButton';
if (stopped){
	but.value = 'Start';
	but.onclick = self.pollServerStart;
}
else{
	but.value = 'Stop';
	but.onclick = self.pollServerStop;
}	
if (buttonDiv.firstChild){
	buttonDiv.removeChild(buttonDiv.firstChild);
}
buttonDiv.appendChild(but);
buttonDiv = null;
}

this.toggleStatusMessage = function(stopped){
	var statSpan = document.getElementById('currentAppState');
	var msg;
	if (stopped){
	msg = 'Stopped';
	}
	else{
	msg = 'Running';
	}
	if (statSpan.firstChild){
	statSpan.removeChild(statSpan.firstChild);
	}
	statSpan.appendChild(document.createTextNode(msg));
};	


this.toggleAppStatus = function(stopped){
var self = Monitor;
self.toggleButton(stopped);
self.toggleStatusMessage(stopped);
};

this.init = function(){
var self = Monitor;
self.targetURL = TARGET_URL;
self.pollInterval = POLL_INTERNVAL;
self.maxPollEntries = MAX_POLL_ENTRIES;
self.timeoutThreshold = TIMEOUT_THRESHOLD;
self.toggleAppStatus(true);
self.reqStatus.init();
};


this.showPoll = function(str) {
 var self = Monitor;
 var diff = 0;
 var end = new Date();
 clearTimeout(self.timeoutHand);
 self.reqStatus.stopProc(true);
 if (str == 'ok') {
   end = end.getTime();
   diff = (end - self.start) / 1000;
 }
 if (self.updatePollArray(diff)) {
   self.printResult();
 }
 self.doPollDelay();
};




this.doPollDelay = function() {
 var self = Monitor;
 self.pollHand = setTimeout(self.doPoll,
     self.pollInterval * 1000);
};

this.pollServerStart = function(){
var self = Monitor;
self.doPoll();
selftoggleAppStatus(false);
//alert('This will start the application');
};

this.pollServerStop = function(){
//alert('This will stop the application');
};


this.handleTimeout = function() {
 alert("Timeout!");
};
this.updatePollArray = function(responseTime) {
 alert("Recording response time: " + responseTime);
};
this.printResult = function() {
 // empty stub function
};


this.doPoll = function() {
 var self = Monitor;
 var url = self.targetURL;
 var start = new Date();
 self.reqStatus.startProc();
 self.start = start.getTime();
 alert(1);
 self.ajax.doGet(self.targetURL + '?start=' + self.start,self.showPoll);
 alert(2);
 self.timeoutHand = setTimeout(self.handleTimeout, self.timeoutThreshold * 1000);
};
}

window.onload = Monitor.init;