Here's some code from my Lynda.com ajax lessons.
var request = new XMLHttpRequest();
request.open('GET', 'data.txt');
request.onreadystatechange = function()
{
if (request.readyState===4)
{
console.log(request);
document.writeln(request.responseText);
}
}
request.send();
In the previous lesson we checked the value of request.status, which was not wrapped in a function, and it worked fine. But now, with no explanation, the request.readyState check has to be wrapped in the function you see above else it won't work. What's going on?