readystate - is an event code
statusText - returns the text of the status code (e.g. "OK" or "Not Found")
onreadystatechange a property of the XHR. Defines a function to be called when the readyState property changes aka the event-handler to be used when the event occurs
State Description
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete
status - is the HTML code returned from the server200: "OK"
403: "Forbidden"
404: "Page not found"
etc
( For a complete list : the Http Messages Reference at W3Schools
In an XMLHttpRequest, the callback function is defined
e.g.
function getCompetition(aFileName) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
// callback function
// called when the XML request status changes
if (this.readyState == 4 && this.status == 200) {
// only interested in the status change of the
// request is both "request complete" and HTML "OK"
competitionDoc = getDoc(this);
console.log("competitionDoc: ", competitionDoc);
// return anXHdoc;
}
};
console.log("About to open the file");
var d = new Date(); var t = d.getTime();
xhttp.open("GET", aFileName + "?" + t , true);
xhttp.send();
}
The callback function section of the function definition of the function containing the XMLHttpRequest (XHR for short from now on) is deferred until the callback is fired by the relevant event
onreadystatechange a property of the XHR. Defines a function to be called when the readyState property changes aka the event-handler to be used when the event occurs
readystatechange an event of XHR Occurs when the readystate attribute changes
readystate an attribute of XHR
Acc, to W3Schools, if you have more than one AJAX task in a website, you should create one function for executing the XMLHttpRequest object, and one callback function for each AJAX task.
This sounds a bit like the refactoring of the requests I was planning on, but I'm not quite sure exactly what they mean.