Have you ever wondered why send
is often called like this?
xhr.send(null)
instead of just
xhr.send()
?
W3, MDN, and MSDN all mention that the argument is optional. Additionally, the ActiveX control seems to work without it:
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.6.0");
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->open("GET", "http://localhost/books.xml ", false);
SUCCEEDED(hr) ? 0 : throw hr;
hr=pIXMLHTTPRequest->send(); // <-- this line
SUCCEEDED(hr) ? 0 : throw hr;
The usage of send(null)
can be traced back to at least as early as 2005 in Google Maps. However, due to minification, there is no clear explanation provided:
Y.asynchronousTransform = function (qc, vb, kc, Nc, Ba) {
if (m.type == 3) return;
var cc = Y.getCached(kc);
if (cc) {
cc.transformToHTML(qc, vb);
if (Nc) Nc();
return
}
var yc = qa.create(Ba);
var sa = Xd.create();
nd('<a href="' + kc.xmlEscape() + '">' + kc.xmlEscape() + "</a>", 0);
sa.open("GET", kc, true);
sa.onreadystatechange = function () {
if (sa.readyState == 4) {
if (yc.isValid()) {
try {
var Db = sa.responseXML;
var cc = Y.create(Db);
Y.cache(kc, cc);
cc.transformToHTML(qc, vb);
if (Nc) Nc()
} catch (b) {}
}
}
};
sa.send(null)
}