为什么send经常被称为
xhr.send(null)而不是
xhr.send()MDN和MSDN都声明它是可选的。此外,ActiveX控制doesn't seem to need the argument
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;send(null)的实践至少可以追溯到2005 in Google Maps,但由于被缩小,没有任何解释:
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)
}发布于 2017-09-20 21:38:02
XMLHttpRequest.send()方法发送请求。如果请求是异步的(这是默认设置),则此方法在发送请求后立即返回。如果请求是同步的,则此方法在响应到达之前不会返回。send()接受请求正文的可选参数。如果请求方法为GET或HEAD,则忽略参数,并将请求正文设置为null。
https://stackoverflow.com/questions/15123839
复制相似问题