So I'm reading a book on AJAX, and they are talking about using inner function as a way to handle multiple requests. I understand that, but in this bit of code they used, I don't understand how the variable XMLHttpRequestObject
can still be used:
if(XMLHttpRequestObject)
{
XMLHttpRequestObject.open(“GET”, dataSource);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
{
document.getElementById(“targetDiv”).innerHTML = XMLHttpRequestObject.responseText;
delete XMLHttpRequestObject;
XMLHttpRequestObject = null;
}
}
XMLHttpRequestObject.send(null);
}
My first qualm is when they delete XMLHttpRequestObject
and then, after it's supposedly deleted, they set it equal to null. Then after it supposedly deleted and set to null, they use the XMLHttpRequestObject.send(null);
But how does it do anything when XMLHttpRequestObject
is deleted and/or contains no value since it's also set to null?