Attempting to create an Ajax request and parse the response header to extract the "Location" attribute. Here is the code in question :
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
if(request.readyState == 4 && request.status == 301) {
alert('test');
let header = request.getResponseHeader('Location');
console.log(header);
}
}
request.open('GET', hrefAttr, true);
request.send(null);
The issue arises when I send the request and receive the response (indicating a red "GET" in Firebug), yet no "test" alert or any output in the firebug console.
MODIFIED CODE:
let request = new XMLHttpRequest();
request.onreadystatechange = function() {
console.log(request.readyState);
if(request.readyState <= 3 && request.status == 301) {
alert('test');
let header = request.getResponseHeader('Location');
console.log(header);
}
else if (request.readyState == 0 && request.status == 301) {
alert('state0');
}
}
request.open('GET', hrefAttr, true);
request.send();
Sequence of states logged with console.log(request.readyState) : 1, 1, 2, 4.
In the Firebug console tab, the Http Request+Response display correctly but appear in red (if that holds significance).
Uncertain as to why it's not functioning... Edit: Utilizing Firefox.
Thank you for your assistance!