Currently, I am working on setting up an AJAX request and I am trying to log each change in the console to ensure that it is functioning correctly. Here is the code snippet:
function loadAJAX() {
ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = readyStateSwitch(ajaxRequest.readyState);
function readyStateSwitch(x) {
switch(x) {
case 0: ajax0(); break;
case 1: ajax1(); break;
case 2: ajax2(); break;
case 3: ajax3(); break;
case 4: ajax4(); break;
default: console.log("no arg"); break;
}
}
function ajax0() {
console.log("0")
}
function ajax1() {
console.log("1")
}
....
ajaxRequest.open("GET", "index.php", true);
ajaxRequest.send();
}
My expectation was to see 0-4 being printed out in the console, but currently only "0" (not initialised) is showing up. Any suggestions for solving this issue?