gpt4 book ai didi

javascript - 为什么我们将 null 传递给 XMLHttpRequest.send?

转载 作者:行者123 更新时间:2023-12-03 00:26:06 28 4
gpt4 key购买 nike

为什么send经常被称为

xhr.send(null)

而不是

xhr.send()

W3 , 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)
}

最佳答案

如果您看一下 XMLHttpRequest 的旧规范,似乎 W3C 并不要求该参数在某一时刻是可选的,这可能导致人们“仅在案例”。

(搜索“应该支持发送”) http://web.archive.org/web/20060409155734/http://www.w3.org/TR/XMLHttpRequest/

我遇到的另一个合理的原因来自俄语页面的翻译,可以在此处查看:long Google Translate link (搜索“GET-Request for Version without ActiveX”)

When you send a GET-request for version without ActiveX, you must specify null, otherwise you can not specify any parameters. Will not fail if GET is always specified null:

我不知道这是否属实,但如果 GET 参数包含在正文中,那么如果数据值“未定义”,则可能不会生成正文,这似乎是合理的。

不幸的是,我在搜索中找不到任何更有说服力的内容。

关于javascript - 为什么我们将 null 传递给 XMLHttpRequest.send?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15123839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com