First is a simple Initialization routine.
function Initialize() {
TalkToServer();
}
The TalkToServer function is just a placeholder to test talking to the server. I had formally used self and I ran into problems with IE so I changed it to myself. Clever, eh? This I am treating as an object rather than just a function. There are four variables; myself, myRequest, scriptsloaded and t another object. There are two methods login and verify. The basic outline is to verify that scripts are loaded and then to perform a login attempt which is just a way to test communication with the server. The username and password are hardcoded because I am just testing communication.
function TalkToServer() {
myself = this;
var myRequest;
var scriptsloaded = false;
var t = new myTimer();
this.login = function() {
myRequest = new ajaxObject('http://kurtclement.com/login.php',processData);
myRequest.update('password=mypassword&username=myusername','POST');
}
this.verify = function() {
if(scriptsloaded) {
myself.login();
} else {
scriptsloaded = VerifyScriptLoaded('tools/tools.js');
t.tryagain(myself.verify,100);
}
}
this.verify();
}
The timer object takes a function and calls that function after the timeout period.
function myTimer() {
var myself = this;
var mymax = 5;
var mycount = 0;
this.tryagain = function(f,t) {
if((mycount++)<mymax) {
setTimeout(function(){myself.what(f);},t);
} else {
alert('max '+mycount);
}
};
myself.what = function(f) {f();};
}