XMLHttpRequest()

The XMLHttpRequest() 构造器初始化一个新的 XMLHttpRequest 对象。

关于 XMLHttpRequest 的具体用法,请参考使用 XMLHttpRequest

语法

js
new XMLHttpRequest()

参数

无。

返回值

一个新的 XMLHttpRequest 对象。此对象 must be prepared by at least calling open() to initialize it before calling send() to send the request to the server.

非标准 Firefox 语法

Firefox 16 added a non-standard parameter to the constructor that can enable anonymous mode (see Firefox bug 692677). Setting the mozAnon flag to true effectively resembles the AnonXMLHttpRequest() constructor described in older versions of the XMLHttpRequest specification.

Gecko/Firefox 16 为该构造方法新增了一个非标准的参数,以启用匿名模式(参见 Firefox bug 692677)。将 mozAnon 属性设置为 true,即可有效地模拟 AnonXMLHttpRequest() 构造器。此构造器在早先的 XMLHttpRequest 规范中有描述,但并未在任何浏览器中被实现。

const request = new XMLHttpRequest(paramsDictionary);

参数(非标准)

objParameters

有两个属性可以设置:

mozAnon

布尔值:将此属性设置为 true 将使浏览器在获取资源时不暴露自身来源和用户凭据。最重要的是,这意味着只有明确添加使用 setRequestHeader 才会发送 Cookies。

mozSystem

布尔值:将此属性设置为 true 允许建立跨站点的连接,而无需服务器选择使用 CORS*(译者注:Cross-Origin Resource Sharing 跨域资源共享)*。必须同时将参数 mozAnon 设置为 true即不能与 Cookie 或其他用户凭据同时发送。仅限于在 privileged (reviewed) apps 起效(译者注:此句原文 This only works in privileged (reviewed) apps;);在 Firefox 上任何网页加载后不起作用(译者注:此句原文 it does not work on arbitrary webpages loaded in Firefox.)。

参见