XMLHttpRequest

现行标准 — 最后更新

参与:
GitHub whatwg/xhr (新问题, 未解决问题)
在Matrix上聊天
提交记录:
GitHub whatwg/xhr/commits
此提交的快照
@xhrstandard
测试:
web-platform-tests xhr/ (正在进行的工作)
翻译 (非规范性)
日本語

摘要

XMLHttpRequest 标准定义了一个API,该API提供了脚本化的客户端功能,用于在客户端和服务器之间传输数据。

1. 介绍

本节为非规范性内容。

XMLHttpRequest 对象是一个用于获取资源的API。

名称XMLHttpRequest 是历史遗留的,名称本身与其功能无关。

一些简单的代码,用于处理通过网络获取的XML文档中的数据:

function processData(data) {
  // 处理数据
}

function handler() {
  if(this.status == 200 &&
    this.responseXML != null &&
    this.responseXML.getElementById('test').textContent) {
    // 成功!
    processData(this.responseXML.getElementById('test').textContent);
  } else {
    // 发生错误}
}

var client = new XMLHttpRequest();
client.onload = handler;
client.open("GET", "unicorn.xml");
client.send();

如果你只想向服务器记录一条消息:

function log(message) {
  var client = new XMLHttpRequest();
  client.open("POST", "/log");
  client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
  client.send(message);
}

或者你想检查服务器上的文档状态:

function fetchStatus(address) {
  var client = new XMLHttpRequest();
  client.onload = function() {
    // 在网络错误的情况下,这可能无法给出可靠的结果
    returnStatus(this.status);
  }
  client.open("HEAD", address);
  client.send();
}

1.1. 规范历史

XMLHttpRequest 对象最初是在WHATWG的HTML工作中定义的。(基于微软多年前的实现。)它于2006年移交给W3C。扩展功能(如进度事件和跨域请求)被单独的草案(XMLHttpRequest Level 2)开发,直到2011年底,此时两个草案合并,XMLHttpRequest 从标准角度再次成为单一实体。到2012年底,它又回到了WHATWG。

当前草案的讨论可以在以下邮件列表档案中找到:

2. 术语

本规范依赖于Infra标准。[INFRA]

本规范使用来自DOM、DOM解析与序列化、编码、Fetch、文件API、HTML、URL、Web IDL和XML的术语。

[DOM] [DOM-PARSING] [ENCODING] [FETCH] [FILEAPI] [HTML] [URL] [WEBIDL] [XML] [XML-NAMES]

3. 接口 XMLHttpRequest

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestEventTarget : EventTarget {
  // 事件处理程序
  attribute EventHandler onloadstart;
  attribute EventHandler onprogress;
  attribute EventHandler onabort;
  attribute EventHandler onerror;
  attribute EventHandler onload;
  attribute EventHandler ontimeout;
  attribute EventHandler onloadend;
};

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestUpload : XMLHttpRequestEventTarget {
};

enum XMLHttpRequestResponseType {
  "",
  "arraybuffer",
  "blob",
  "document",
  "json",
  "text"
};

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequest : XMLHttpRequestEventTarget {
  constructor();

  // 事件处理程序
  attribute EventHandler onreadystatechange;

  // 状态
  const unsigned short UNSENT = 0;
  const unsigned short OPENED = 1;
  const unsigned short HEADERS_RECEIVED = 2;
  const unsigned short LOADING = 3;
  const unsigned short DONE = 4;
  readonly attribute unsigned short readyState;

  // 请求
  undefined open(ByteString method, USVString url);
  undefined open(ByteString method, USVString url, boolean async, optional USVString? username = null, optional USVString? password = null);
  undefined setRequestHeader(ByteString name, ByteString value);
           attribute unsigned long timeout;
           attribute boolean withCredentials;
  [SameObject] readonly attribute XMLHttpRequestUpload upload;
  undefined send(optional (Document or XMLHttpRequestBodyInit)? body = null);
  undefined abort();

  // 响应
  readonly attribute USVString responseURL;
  readonly attribute unsigned short status;
  readonly attribute ByteString statusText;
  ByteString? getResponseHeader(ByteString name);
  ByteString getAllResponseHeaders();
  undefined overrideMimeType(DOMString mime);
           attribute XMLHttpRequestResponseType responseType;
  readonly attribute any response;
  readonly attribute USVString responseText;
  [Exposed=Window] readonly attribute Document? responseXML;
};

一个XMLHttpRequest 对象关联了:

上传对象
一个XMLHttpRequestUpload 对象。
状态
其中之一:未发送已打开头信息已接收加载中已完成; 初始状态为未发送
send()标志
一个标志,初始未设置。
超时时间
一个无符号整数,初始为0。
跨域凭据
一个布尔值,初始为false。
请求方法
一个方法
请求URL
一个URL
自定义请求头
一个头信息列表,初始为空。
请求体
初始为null。
同步标志
一个标志,初始未设置。
上传完成标志
一个标志,初始未设置。
上传监听标志
一个标志,初始未设置。
超时标志
一个标志,初始未设置。
响应
一个响应,初始为网络错误
接收的字节
一个字节序列,初始为空字节序列。
响应类型
以下之一:空字符串、"arraybuffer"、"blob"、 "document"、"json"和"text";初始为空字符串。
响应对象
一个对象、失败或null,初始为null。
请求控制器
一个请求控制器,初始为一个新的请求控制器send() 方法被调用时会设置为一个有用的请求控制器,但为简单起见,它总是持有一个请求控制器
覆盖的MIME类型
一个MIME类型或null,初始为null。在调用overrideMimeType() 时可以获取值。

3.1. 构造函数

client = new XMLHttpRequest()
返回一个新的XMLHttpRequest 对象。

new XMLHttpRequest() 构造函数的步骤如下:

  1. this上传对象设置为一个新的 XMLHttpRequestUpload对象。

3.2. 垃圾回收

XMLHttpRequest 对象的状态已打开,且设置了send()标志, 或者状态为头信息已接收加载中,并且注册了一个或多个事件监听器时,该对象不能被垃圾回收。事件类型为:readystatechangeprogressaborterrorloadtimeout、 和loadend

如果一个XMLHttpRequest 对象在其连接仍然打开的情况下被垃圾回收,用户代理必须终止XMLHttpRequest 对象的请求控制器

3.3. 事件处理程序

以下是事件处理程序(及其对应的事件类型) ,在继承自XMLHttpRequestEventTarget接口的对象上必须作为属性支持:

事件处理程序 事件类型
onloadstart loadstart
onprogress progress
onabort abort
onerror error
onload load
ontimeout timeout
onloadend loadend

以下是事件处理程序(及其对应的事件类型),仅在XMLHttpRequest 对象上作为属性支持:

事件处理程序 事件类型
onreadystatechange readystatechange

3.4. 状态

client . readyState

返回client状态

readyState获取步骤如下,返回表格第二列的值,对应第一列中this状态

未发送 UNSENT(数值 0) 对象已构建。
已打开 OPENED(数值 1) open()方法已成功调用。在此状态下,可以使用setRequestHeader()设置请求头,并使用send()方法发起请求。
头信息已接收 HEADERS_RECEIVED (数值 2) 所有重定向(如果有)已跟随,所有响应头信息已接收。
加载中 LOADING(数值 3) 响应体正在接收中。
已完成 DONE(数值 4) 数据传输已完成,或传输过程中出现问题(如无限重定向)。

3.5. 请求

XMLHttpRequestUpload 对象上注册一个或多个事件监听器将导致一个CORS预检请求。(这是因为注册事件监听器会导致上传监听标志被设置,而这会导致使用CORS预检标志被设置。)

3.5.1. open()方法

client . open(method, url [, async = true [, username = null [, password = null]]])

设置请求方法请求URL,以及同步标志

如果method不是有效方法,或者url无法解析,则抛出"SyntaxError"DOMException

如果method与`CONNECT`、`TRACE`或`TRACK`不区分大小写匹配,则抛出"SecurityError"DOMException

如果async为false,当前全局对象是Window对象,且timeout属性不为零,或者responseType属性不为空,则抛出"InvalidAccessError"DOMException

在非工作者环境中的同步XMLHttpRequest正在逐步从Web平台移除,因为它对终端用户体验有不利影响。(这是一个需要多年才能完成的过程。)开发者不得在Window对象作为当前全局对象时传递async参数为false。用户代理强烈建议在开发者工具中对此类用法发出警告,并可尝试抛出一个"InvalidAccessError"DOMException

open(method, url)open(method, url, async, username, password)方法的步骤如下:

  1. 如果this相关全局对象是一个Window对象,并且其相关Document不是完全活动状态,则抛出一个"InvalidStateError" DOMException

  2. 如果method不是有效方法,则抛出一个"SyntaxError"DOMException

  3. 如果method是一个禁用方法,则抛出一个"SecurityError"DOMException

  4. 规范化method

  5. parsedURL设置为通过编码解析URL url的结果,相对于this相关设置对象

  6. 如果parsedURL解析失败,则抛出一个"SyntaxError"DOMException

  7. 如果未指定async参数,则将async设置为true,并将usernamepassword设置为null。

    遗憾的是,遗留内容阻止了将async参数为undefined的情况与省略该参数视为相同。

  8. 如果parsedURL主机非空,则:

    1. 如果username参数不为null,设置用户名parsedURLusername

    2. 如果password参数不为null,设置密码parsedURLpassword

  9. 如果async为false,当前全局对象是一个Window对象,并且thistimeout不为0,或者thisresponse type不为空,则抛出一个"InvalidAccessError"DOMException

  10. 终止thisfetch控制器

    此时可能仍有一个fetch正在进行。

  11. 将对象相关的变量设置如下:

    覆盖的MIME类型不会在此被覆盖,因为overrideMimeType()方法可以在open()方法之前调用。

  12. 如果this状态不是opened,则:

    1. this状态设置为opened

    2. 触发一个事件,事件名为readystatechange,在this上。

定义了两个open()方法的原因是由于编写XMLHttpRequest标准时使用的编辑软件的限制。

3.5.2. setRequestHeader() 方法

client . setRequestHeader(name, value)

将一个值追加到现有请求头,或添加一个新的请求头。

如果状态不是opened,或send()标志已设置,则抛出 "InvalidStateError" DOMException

如果name不是一个头名称,或者value不是头值,则抛出"SyntaxError" DOMException

setRequestHeader(name, value) 方法必须按以下步骤执行:

  1. 如果this状态不是opened,则抛出 "InvalidStateError" DOMException

  2. 如果thissend()标志已设置,则抛出 "InvalidStateError" DOMException

  3. 规范化 value

  4. 如果name不是头名称,或value不是头值,则抛出 "SyntaxError" DOMException

    空字节序列表示空的头值

  5. 如果 (name, value) 是一个禁止的请求头,则返回。

  6. 合并 (name, value) 到this作者请求头

下面的代码演示了当设置同一个头两次时发生了什么:

// 下面的脚本:
var client = new XMLHttpRequest();
client.open('GET', 'demo.cgi');
client.setRequestHeader('X-Test', 'one');
client.setRequestHeader('X-Test', 'two');
client.send();

// ……结果发送了如下头:
// X-Test: one, two

3.5.3. timeout 获取器和设置器

client . timeout

可以设置为以毫秒为单位的时间。当设置为非零值时,在指定时间过去后,如果fetch 还没有完成,并且this同步标志未设置,则会触发一个timeout事件,否则将抛出一个 "TimeoutError" DOMException

设置时:如果同步标志设置了,并且当前全局对象Window对象,则抛出一个 "InvalidAccessError" DOMException

timeout 获取器步骤为返回thistimeout

timeout 设置器步骤为:

  1. 如果当前全局对象Window对象,并且this同步标志设置了,则抛出 "InvalidAccessError" DOMException

  2. 设置thistimeout为给定值。

这意味着timeout 属性可以在fetch进行过程中被设置。如果发生这种情况,仍然会相对于fetch的开始时间进行计时。

3.5.4. withCredentials 获取器和设置器

client . withCredentials

在跨域请求中,当凭证被包含时为 true,当它们被排除并且响应中忽略 cookie 时为 false。默认值为 false。

设置时:如果状态不是 unsentopened,或者send() 标志已设置,则抛出 "InvalidStateError" DOMException

withCredentials 获取器步骤为返回this跨域凭证

withCredentials 设置器步骤为:

  1. 如果this状态不是 unsentopened,则抛出 "InvalidStateError" DOMException

  2. 如果thissend() 标志已设置,则抛出 "InvalidStateError" DOMException

  3. 设置this跨域凭证为给定值。

3.5.5. upload 获取器

client . upload

返回关联的 XMLHttpRequestUpload 对象。它可以用于在数据传输到服务器时收集传输信息。

upload 获取器步骤是返回 this上传对象

3.5.6. send() 方法

client . send([body = null])

启动请求。body 参数提供了 请求体(如果有的话), 如果 请求方法GETHEAD,则忽略该参数。

如果 状态 不是 opened 或者 send() 标志已设置,抛出 "InvalidStateError" DOMException

send(body) 方法的步骤为:

  1. 如果 thisstate 不是 opened,则 抛出 "InvalidStateError" DOMException

  2. 如果 thissend() 标志已设置, 则 抛出 "InvalidStateError" DOMException

  3. 如果 this请求方法 是 `GET` 或 `HEAD`,则将 body 设置为 null。

  4. 如果 body 不是 null,则:

    1. extractedContentType 为 null。

    2. 如果 body 是一个 Document,则将 this请求体 设置为 body序列化转换,并以 UTF-8 编码

    3. 否则:

      1. bodyWithType 成为安全提取 body 的结果。

      2. this请求体 设置为 bodyWithTypebody

      3. extractedContentType 设置为 bodyWithType类型

    4. originalAuthorContentType 成为 获取 `Content-Type` 从 this作者请求头 的结果。

    5. 如果 originalAuthorContentType 不为 null,则:

      1. 如果 body 是一个 Document 或一个 USVString,则:

        1. contentTypeRecord 成为 解析 originalAuthorContentType 的结果。

        2. 如果 contentTypeRecord 不是失败,contentTypeRecord参数["charset"] 存在, 且 参数["charset"] 不是 ASCII不区分大小写匹配 "UTF-8",则:

          1. 设置 contentTypeRecord参数["charset"] 为 "UTF-8"。

          2. newContentTypeSerialized 成为 序列化 contentTypeRecord 的结果。

          3. 设置 (`Content-Type`, newContentTypeSerialized) 到 this作者请求头 中。

    6. 否则:

      1. 如果 body 是一个 HTML文档,则 设置 (`Content-Type`, `text/html;charset=UTF-8`) 到 this作者请求头 中。

      2. 否则,如果 body 是一个 XML文档,则 设置 (`Content-Type`, `application/xml;charset=UTF-8`) 到 this作者请求头 中。

      3. 否则,如果 extractedContentType 不为 null,则 设置 (`Content-Type`, extractedContentType) 到 this作者请求头 中。

  5. 如果一个或多个事件监听器被注册到 this上传对象,则设置 this上传监听器标志

  6. req 成为一个新的 请求,初始化如下:

    方法
    请求方法
    URL
    请求 URL
    头列表
    作者请求头
    不安全请求标志
    设置。
    请求体
    请求体
    客户端
    相关设置对象
    模式
    "cors"。
    使用 CORS 预检标志
    如果 上传监听器标志已设置。
    凭证模式
    如果 跨源凭证 为 true,则 "include"; 否则 "same-origin"。
    使用 URL 凭证标志
    如果 请求 URL 包括凭证
    发起者类型
    "xmlhttprequest"。
  7. 取消设置 上传完成标志

  8. 取消设置 超时标志

  9. 如果 req请求体为 null,则设置 上传完成标志

  10. 设置 send()标志

  11. 如果 同步标志未设置,则:

    1. 触发进度事件名为 loadstart,并传递 0 和 0。

    2. requestBodyTransmitted 为 0。

    3. requestBodyLengthreq请求体长度,如果 req请求体非空;否则为 0。

    4. 断言:requestBodyLength 是一个整数。

    5. 如果 上传完成标志未设置且 上传监听器标志已设置,则 触发进度事件名为 loadstart上传对象,并传递 requestBodyTransmittedrequestBodyLength

    6. 如果 状态不是 已打开,或 send() 标志未设置,则返回。

    7. processRequestBodyChunkLength,给定一个 bytesLength,执行以下步骤:

      1. requestBodyTransmitted 增加 bytesLength

      2. 如果自上次调用这些步骤以来大约没有经过 50 毫秒,则返回。

      3. 如果 上传监听器标志已设置,则 触发一个进度事件名为 progress上传对象,传递 requestBodyTransmittedrequestBodyLength

      这些步骤仅在传输新字节时调用。

    8. processRequestEndOfBody 执行以下步骤:

      1. 设置 上传完成标志

      2. 如果 上传监听器标志未设置,则返回。

      3. 触发一个进度事件名为 progress上传对象,传递 requestBodyTransmittedrequestBodyLength

      4. 触发一个进度事件名为 load上传对象,传递 requestBodyTransmittedrequestBodyLength

      5. 触发一个进度事件名为 loadend上传对象,传递 requestBodyTransmittedrequestBodyLength

    9. processResponse,给定一个 response,执行以下步骤:

      1. 响应 设置为 response

      2. 处理错误

      3. 如果 响应 是一个 网络错误,则返回。

      4. 设置 状态头接收

      5. 触发一个事件 名为 readystatechange

      6. 如果 状态 不是 头接收,则返回。

      7. 如果 响应主体为 null,则为 处理响应主体结束 并返回。

      8. length提取的长度从 响应头列表

      9. 如果 length 不是一个整数,则将其设置为 0。

      10. processBodyChunk 给定 bytes,执行以下步骤:

        1. bytes 附加到 接收到的字节

        2. 如果自上次调用这些步骤以来大约没有经过 50 毫秒,则返回。

        3. 如果 状态已接收头部,则将 状态设置为加载中

        4. 触发一个事件名为 readystatechange

          出于 Web 兼容性的原因,readystatechange 事件触发的频率要比 状态 更频繁。

        5. 触发一个进度事件名为 progress,传递 接收到的字节长度length

      11. processEndOfBody 设为此步骤:为 处理响应的结束部分 运行 此对象

      12. processBodyError 设为以下步骤:

        1. 此对象响应 设为 网络错误

        2. 处理错误 运行 此对象

      13. 根据 processBodyChunkprocessEndOfBodyprocessBodyError此对象相关全局对象逐步读取 此对象响应主体

    10. 此对象fetch 控制器 设置为 fetching req 的结果,其中 processRequestBodyChunkLength 设置为 processRequestBodyChunkLengthprocessRequestEndOfBody 设置为 processRequestEndOfBodyprocessResponse 设置为 processResponse

    11. now 设为当前时间。

    12. 并行运行以下步骤:并行

      1. 等待直到 req完成标志 被设置,或 此对象超时时间 不为 0 并且自 now 以来已经过去了 超时时间 毫秒。

      2. 如果 req完成标志 未设置,则将 此对象超时标志 设置并终止 此对象fetch 控制器

  12. 否则,如果 此对象同步标志 已设置:

    1. processedResponse 设为 false。

    2. processResponseConsumeBody 设为以下步骤,给定 responsenullOrFailureOrBytes

      1. 如果 nullOrFailureOrBytes 不是失败,则将 此对象响应 设置为 response

      2. 如果 nullOrFailureOrBytes字节序列,则将 nullOrFailureOrBytes 添加到 此对象接收到的字节

      3. processedResponse 设置为 true。

    3. 此对象fetch 控制器 设置为 fetching req 的结果,processResponseConsumeBody 设置为 processResponseConsumeBody,并将 useParallelQueue 设置为 true。

    4. now 设为当前时间。

    5. 暂停 直到 processedResponse 为 true 或 此对象超时 不为 0,并且自 now 以来已经过去了 超时时间 毫秒。

    6. 如果 processedResponse 为 false,则将 此对象超时标志 设置,并终止 此对象fetch 控制器

    7. 报告时间,针对 此对象fetch 控制器,给定 当前全局对象

    8. 处理响应的结束部分 运行 此对象

XMLHttpRequest 对象 xhr 处理响应结束部分,运行以下步骤:

  1. xhr 处理错误

  2. 如果 xhr响应网络错误,则返回。

  3. transmitted 设为 xhr接收到的字节长度

  4. length 设为从 此对象响应头部列表提取的长度的结果。

  5. 如果 length 不是整数,则将其设为 0。

  6. 如果 xhr同步标志 未设置,则在 xhr 上,使用 transmittedlength 触发一个名为 progress 的进度事件。

  7. xhr状态 设置为 完成

  8. 取消 xhrsend() 标志

  9. xhr触发一个名为 readystatechange 的事件。

  10. xhr 上,使用 transmittedlength 触发一个名为 load 的进度事件。

  11. xhr 上,使用 transmittedlength 触发一个名为 loadend 的进度事件。

XMLHttpRequest 对象 xhr 处理错误,运行以下步骤:

  1. 如果 xhrsend() 标志 未设置,则返回。

  2. 如果 xhr超时标志 已设置,则为 xhr 运行 请求错误步骤timeout,并使用“TimeoutErrorDOMException

  3. 否则,如果 xhr响应终止标志 已设置,则为 xhr 运行 请求错误步骤abort,并使用“AbortErrorDOMException

  4. 否则,如果 xhr响应网络错误,则为 xhr 运行 请求错误步骤error, 并使用“NetworkErrorDOMException

XMLHttpRequest 对象 xhrevent 和可选的 exception 执行 请求错误步骤

  1. xhr状态 设置为 完成

  2. 取消 xhrsend() 标志

  3. xhr响应 设为 网络错误

  4. 如果 xhr同步标志 已设置,则 抛出 exception

  5. xhr触发一个名为 readystatechange 的事件。

    此时显然 xhr同步标志 未设置。

  6. 如果 xhr上传完成标志 未设置,则:

    1. xhr上传完成标志 设置。

    2. 如果 xhr上传监听器标志 已设置,则:

      1. xhr上传对象触发一个名为 event 的进度事件,使用 0 和 0。

      2. xhr上传对象触发一个名为 loadend 的进度事件,使用 0 和 0。

  7. xhr触发一个名为 event 的进度事件,使用 0 和 0。

  8. xhr触发一个名为 loadend 的进度事件,使用 0 和 0。

3.5.7. abort() 方法

client . abort()
取消任何网络活动。

abort() 方法步骤为:

  1. 终止 此对象fetch 控制器

  2. 如果 此对象状态打开send() 标志已设置,已接收头部加载中,则为 此对象 运行 请求错误步骤abort

  3. 如果 此对象状态完成,则将 此对象状态设置为 未发送,并将 此对象响应设置为 网络错误

    不会派发 readystatechange 事件。

3.6. 响应

3.6.1. responseURL 获取器

responseURL 获取器的步骤是,如果 此对象响应URL 为空,则返回空字符串; 否则返回其设置了 排除片段标志序列化结果。

3.6.2. status 获取器

status 获取器的步骤是返回 此对象响应状态

3.6.3. statusText 获取器

statusText 获取器的步骤是返回 此对象响应状态消息

3.6.4. getResponseHeader() 方法

getResponseHeader(name) 方法步骤是返回从 此对象响应头部列表中获取 name 的结果。

Fetch 标准过滤了 此对象响应头部列表[FETCH]

对于以下脚本:

var client = new XMLHttpRequest();
client.open("GET", "unicorns-are-awesome.txt", true);
client.send();
client.onreadystatechange = function() {
  if(this.readyState == this.HEADERS_RECEIVED) {
    print(client.getResponseHeader("Content-Type"));
  }
}

print() 函数将处理类似的内容:

text/plain; charset=UTF-8

3.6.5. getAllResponseHeaders() 方法

如果以下步骤返回 true,则字节序列 a 被定义为 传统大写字节小于 字节序列 b

  1. A 设为 a大写字节

  2. B 设为 b大写字节

  3. 返回 A 是否 小于 B

getAllResponseHeaders() 方法的步骤是:

  1. output 设为空字节序列。

  2. initialHeaders 设为对 此对象响应头部列表 执行 排序和合并 的结果。

  3. headers 设为对 initialHeaders 进行 升序排序 的结果,其中当 a名称b 的名称 传统大写字节小于 时,a 小于 b

    不幸的是,这在与已部署内容的兼容性方面是必要的。

  4. 对于每个 headerheaders 中,附加 header名称,后跟 0x3A 0x20 字节对,再跟 header,最后跟 0x0D 0x0A 字节对,添加到 output

  5. 返回 output

Fetch 标准过滤了 此对象响应头部列表[FETCH]

对于以下脚本:

var client = new XMLHttpRequest();
client.open("GET", "narwhals-too.txt", true);
client.send();
client.onreadystatechange = function() {
  if(this.readyState == this.HEADERS_RECEIVED) {
    print(this.getAllResponseHeaders());
  }
}

print() 函数将处理类似的内容:

connection: Keep-Alive
content-type: text/plain; charset=utf-8
date: Sun, 24 Oct 2004 04:58:38 GMT
keep-alive: timeout=15, max=99
server: Apache/1.3.31 (Unix)
transfer-encoding: chunked

3.6.6. 响应主体

要为 XMLHttpRequest 对象 xhr 获取响应 MIME 类型,执行以下步骤:

  1. mimeType 设为从 xhr响应头部列表提取 MIME 类型 的结果。

  2. 如果 mimeType 失败,则将 mimeType 设置为 text/xml

  3. 返回 mimeType

要为 XMLHttpRequest 对象 xhr 获取最终的 MIME 类型,执行以下步骤:

  1. 如果 xhr覆盖 MIME 类型 为空,则返回为 xhr 获取响应 MIME 类型 的结果。

  2. 返回 xhr覆盖 MIME 类型

要为 XMLHttpRequest 对象 xhr 获取最终编码,执行以下步骤:

  1. label 设为空。

  2. responseMIME 设为为 xhr 获取响应 MIME 类型 的结果。

  3. 如果 responseMIME参数["charset"] 存在, 则将 label 设置为它。

  4. 如果 xhr覆盖 MIME 类型参数["charset"] 存在, 则将 label 设置为它。

  5. 如果 label 为空,则返回空。

  6. encoding 设为从 label 获取编码 的结果。

  7. 如果 encoding 失败,则返回空。

  8. 返回 encoding

以上步骤故意不使用 获取最终 MIME 类型,因为这将不与 Web 兼容。


要为 XMLHttpRequest 对象 xhr 设置文档响应,执行以下步骤:

  1. 如果 xhr响应主体 为空,则返回。

  2. finalMIME 设为为 xhr 获取最终 MIME 类型 的结果。

  3. 如果 finalMIME 不是 HTML MIME 类型XML MIME 类型,则返回。

  4. 如果 xhr响应类型 为空字符串且 finalMIMEHTML MIME 类型,则返回。

    这是限制 xhr响应类型 为 "document" 以防止破坏遗留内容。

  5. 如果 finalMIMEHTML MIME 类型, 则:

    1. charset 设为为 xhr 获取最终编码 的结果。

    2. 如果 charset 为空,则预扫描 xhr 的前 1024 字节的 接收到的字节,如果该操作未失败,则将 charset 设置为返回值。

    3. 如果 charset 为空,则将 charset 设置为 UTF-8

    4. document 设为 文档,其表示按照 HTML 标准中关于禁用脚本的 HTML 解析器和确定编码 charset 解析 xhr接收到的字节的结果。 [HTML]

    5. document 标记为 HTML 文档

  6. 否则,将 document 设为 文档,其表示在 xhr接收到的字节上运行 XML 解析器且禁用XML 脚本支持 的结果。如果失败(不支持的字符编码、命名空间格式错误等),则返回空。 [HTML]

    不会加载引用的资源,也不会应用任何相关的 XSLT。

  7. 如果 charset 为空,则将 charset 设置为 UTF-8

  8. document编码设置为 charset

  9. document内容类型设置为 finalMIME

  10. documentURL设置为 xhr响应URL

  11. document来源设置为 xhr相关设置对象来源

  12. xhr响应对象 设置为 document

要为 XMLHttpRequest 对象 xhr 获取文本响应,执行以下步骤:

  1. 如果 xhr响应主体 为空,则返回空字符串。

  2. charset 设为为 xhr 获取最终编码 的结果。

  3. 如果 xhr响应类型为空字符串,charset为空,且为 xhr 获取最终 MIME 类型 的结果为 XML MIME 类型,则使用 XML 规范中规定的规则确定编码。将 charset 设置为确定的编码。 [XML] [XML-NAMES]

    这是为了保持非遗留的 xhr 响应类型值 "text" 的简洁。

  4. 如果 charset 为空,则将 charset 设置为 UTF-8

  5. 返回在 xhr接收到的字节上使用回退编码 charset 解码的结果。

作者强烈建议始终使用 UTF-8 编码其资源。

3.6.7. overrideMimeType() 方法

client . overrideMimeType(mime)

作用是使响应的 `Content-Type` 头部值看起来像是 mime。(它不会更改头部。)

如果 状态loadingdone,则抛出 "InvalidStateError" DOMException

overrideMimeType(mime) 方法的步骤为:

  1. 如果 此对象状态loadingdone,则 抛出 "InvalidStateError" DOMException

  2. 此对象覆盖 MIME 类型 设置为对 mime 解析 的结果。

  3. 如果 此对象覆盖 MIME 类型 失败,则将 此对象覆盖 MIME 类型 设置为 application/octet-stream

3.6.8. responseType 获取器和设置器

client . responseType [ = value ]

返回响应类型。

可以设置以更改响应类型。值包括: 空字符串(默认), "arraybuffer", "blob", "document", "json" 和 "text"。

设置时:如果 当前全局对象 不是 Window 对象,则忽略设置为 "document"。

设置时:如果 InvalidStateError DOMException 将被抛出,如果 状态loadingdone

设置时:如果 InvalidAccessError DOMException 将被抛出,如果 同步标志 已设置并且 当前全局对象Window 对象。

responseType 获取器的步骤是返回 此对象响应类型

responseType 设置器的步骤为:

  1. 如果 当前全局对象 不是 Window 对象且给定值为 "document",则返回。

  2. 如果 此对象状态loadingdone,则 抛出 "InvalidStateError" DOMException

  3. 如果 当前全局对象Window 对象并且 此对象同步标志 已设置,则 抛出 "InvalidAccessError" DOMException

  4. 此对象响应类型 设置为给定值。

3.6.9. response 获取器

client . response

返回响应主体。

response 获取器的步骤为:

  1. 如果 此对象响应类型为空字符串或 "text",则:

    1. 如果 此对象状态 不是 loadingdone,则返回空字符串。

    2. 返回为 此对象 获取文本响应 的结果。

  2. 如果 此对象状态 不是 done,则返回 null。

  3. 如果 此对象响应对象 失败,则返回 null。

  4. 如果 此对象响应对象 非空,则返回它。

  5. 如果 此对象响应类型 为 "arraybuffer",则将 此对象响应对象 设置为表示 此对象 接收到的字节ArrayBuffer 对象。如果此操作抛出异常,则将 此对象响应对象 设置为失败并返回 null。

    分配 ArrayBuffer 对象不能保证成功。 [ECMASCRIPT]

  6. 否则,如果 此对象响应类型 为 "blob",则将 此对象响应对象 设置为表示 此对象接收到的字节Blob 对象,并将 type 设置为为 此对象 获取最终 MIME 类型 的结果。

  7. 否则,如果 此对象响应类型 为 "document",则 设置文档响应此对象

  8. 否则:

    1. 断言:此对象响应类型 为 "json"。

    2. 如果 此对象响应主体为空,则返回 null。

    3. jsonObject 设为对 此对象接收到的字节运行 从字节解析 JSON 的结果。如果此操作抛出异常,则返回 null。

    4. 此对象响应对象 设置为 jsonObject

  9. 返回 此对象响应对象

3.6.10. responseText 获取器

client . responseText

返回响应为文本格式。

如果 responseType 不是空字符串或 "text", 则抛出 "InvalidStateError" DOMException

responseText 获取器的步骤为:

  1. 如果 此对象响应类型 不是空字符串或 "text",则 抛出 "InvalidStateError" DOMException

  2. 如果 此对象状态 不是 loadingdone,则返回空字符串。

  3. 返回为 此对象 获取文本响应 的结果。

3.6.11. responseXML 获取器

client . responseXML

返回响应为文档格式。

如果 responseType 不是空字符串或 "document", 则抛出 "InvalidStateError" DOMException

responseXML 获取器的步骤为:

  1. 如果 this响应类型 不是空字符串或 "document",则 抛出 "InvalidStateError" DOMException

  2. 如果 this状态 不是 done, 则返回 null。

  3. 断言:this响应对象 没有失败。

  4. 如果 this响应对象 非空,则返回它。

  5. 设置文档响应this

  6. 返回 this响应对象

3.7. 事件概要

本节为非规范性内容。

以下事件会在 XMLHttpRequestXMLHttpRequestUpload 对象上被触发:

事件名称 接口 触发时机……
readystatechange Event readyState 属性改变时触发,除了它改变为 UNSENT 时。
loadstart ProgressEvent 请求开始时触发。
progress ProgressEvent 数据传输时触发。
abort ProgressEvent 请求被中止时触发。例如,通过调用 abort() 方法。
error ProgressEvent 请求失败时触发。
load ProgressEvent 请求成功时触发。
timeout ProgressEvent 在请求超时时触发。
loadend ProgressEvent 请求完成(无论成功或失败)时触发。

4. 接口 FormData

typedef (File or USVString) FormDataEntryValue;

[Exposed=(Window,Worker)]
interface FormData {
  constructor(optional HTMLFormElement form, optional HTMLElement? submitter = null);

  undefined append(USVString name, USVString value);
  undefined append(USVString name, Blob blobValue, optional USVString filename);
  undefined delete(USVString name);
  FormDataEntryValue? get(USVString name);
  sequence<FormDataEntryValue> getAll(USVString name);
  boolean has(USVString name);
  undefined set(USVString name, USVString value);
  undefined set(USVString name, Blob blobValue, optional USVString filename);
  iterable<USVString, FormDataEntryValue>;
};

每个 FormData 对象都有一个关联的 entry list (一个 条目列表)。它最初是空的。

本节曾定义了 条目、条目的 名称,以及 创建条目 的算法。这些定义已被移至 HTML 标准中。[HTML]

new FormData(form, submitter) 构造器步骤如下:

  1. 如果 form 被提供,则:

    1. 如果 submitter 非空,则:

      1. 如果 submitter 不是 提交按钮,则 抛出 一个 TypeError

      2. 如果 submitter表单所有者 不是 form,则 抛出一个 "NotFoundError" DOMException

    2. list构建表单数据集 的结果,针对 formsubmitter

    3. 如果 list 为 null,则 抛出 一个 "InvalidStateError" DOMException

    4. this条目列表 设置为 list

append(name, value)append(name, blobValue, filename) 方法步骤如下:

  1. 如果给定值,则将 value 设为 value;否则设为 blobValue

  2. entry 为通过 创建条目 得到的结果,使用 namevalue 和可选的 filename

  3. entry 添加到 this条目列表 中。

参数 valueblobValue 同时存在的原因是因为用于编写 XMLHttpRequest 标准的编辑软件的限制。

delete(name) 方法步骤是 删除 所有 名称为 name条目

get(name) 方法的步骤如下:

  1. 如果 entry 中没有名称为 namethis条目列表,则返回 null。

  2. 返回第一个名称为 nameentryvalue,从 this条目列表 中。

getAll(name) 方法的步骤如下:

  1. 如果 entry 中没有名称为 namethis条目列表,则返回空列表。

  2. 返回所有名称为 nameentry,按顺序从 this条目列表 中。

has(name) 方法的步骤是:如果 entry 中有名称为 name 的条目存在于 this条目列表 中,则返回 true;否则返回 false。

set(name, value)set(name, blobValue, filename) 方法的步骤如下:

  1. 如果给定了 value,则令其为 value;否则令其为 blobValue

  2. 使用 namevalue 和(如果给定)filename 的值,执行 创建条目 的操作,令其结果为 entry

  3. 如果在 this条目列表 中有名称为 name条目,则 替换第一个这样的 条目entry,并 移除其他条目。

  4. 否则,追加 entrythis条目列表 中。

命名为 valueblobValue 的参数是由于编写 XMLHttpRequest 标准时使用的编辑软件的限制。

要迭代的键值对this条目列表 中的 条目,键为 名称,值为

5. 接口 ProgressEvent

[Exposed=(Window,Worker)]
interface ProgressEvent : Event {
  constructor(DOMString type, optional ProgressEventInit eventInitDict = {});

  readonly attribute boolean lengthComputable;
  readonly attribute double loaded;
  readonly attribute double total;
};

dictionary ProgressEventInit : EventInit {
  boolean lengthComputable = false;
  double loaded = 0;
  double total = 0;
};

事件 使用 ProgressEvent 接口表示某种进展。

lengthComputableloadedtotal getter 的步骤是返回它们的初始值。

5.1. 使用 ProgressEvent 接口触发事件

为了 触发一个名为 e 的进度事件target 上,给定 transmittedlength,意味着使用 触发一个事件 名为 etarget 上,使用 ProgressEvent,并将 loaded 属性初始化为 transmitted,如果 length 不为 0,则将 lengthComputable 属性初始化为 true,并将 total 属性初始化为 length

5.2. 使用 ProgressEvent 接口的建议事件名称

本节非规范性。

使用 事件ProgressEvent 接口时,建议的 type 属性值总结在下表中。规范编辑者可以根据具体情况调整细节,但强烈建议与 WHATWG 社区讨论他们的使用,以确保从熟悉该主题的人那里获得意见。

type 属性值 描述 次数 时间点
loadstart 进度开始。 一次。 最初。
progress 正在进行。 一次或多次。 loadstart分发之后。
error 进度失败。 零次或一次(互斥)。 在最后一个 progress分发之后。
abort 进度被终止。
timeout 由于预设时间到期,进度被终止。
load 进度成功。
loadend 进度停止。 一次。 erroraborttimeoutload 之一被 分发之后。

erroraborttimeoutload 事件类型是互斥的。

在整个 Web 平台中,erroraborttimeoutload 事件类型的 bubblescancelable 属性初始值为 false,因此建议为了保持一致,所有使用 事件ProgressEvent 接口的事件都遵循此规则。

5.3. 安全注意事项

对于跨域请求,需要某种类型的选择加入,例如 Fetch 标准中定义的 CORS 协议,在 事件 使用 ProgressEvent 接口之前,因为会泄露无法通过其他方式获得的信息(例如大小)。[FETCH]

5.4. 示例

在这个示例中,XMLHttpRequest 与前述章节中定义的概念相结合,使用 HTML 的 progress 元素一起显示获取资源的过程。

<!DOCTYPE html>
<title>Waiting for Magical Unicorns</title>
<progress id=p></progress>
<script>
  var progressBar = document.getElementById("p"),
      client = new XMLHttpRequest()
  client.open("GET", "magical-unicorns")
  client.onprogress = function(pe) {
    if(pe.lengthComputable) {
      progressBar.max = pe.total
      progressBar.value = pe.loaded
    }
  }
  client.onloadend = function(pe) {
    progressBar.value = pe.loaded
  }
  client.send()
</script>

完整可运行的代码当然会更加复杂,并处理更多场景,例如网络错误或终端用户终止请求的情况。

致谢

感谢 Addison Phillips, Adrian Bateman, Ahmed Kamel, Alan Thomas, Alex Hopmann, Alex Vincent, Alexey Proskuryakov, Ali Alabbas, Andrea Marchesini, Asbjørn Ulsberg, Bertrand Guay-Paquet, Björn Höhrmann, Boris Zbarsky, Caitlin Potter, Cameron McCormack, 白丞祐 (Cheng-You Bai), Chris Marrin, Christophe Jolif, Charles McCathieNevile, Chirag S Kumar, Dan Winship, David Andersson, David Flanagan, David Håsäther, David Levin, Dean Jackson, Denis Sureau, Domenic Denicola, Dominik Röttsches, Doug Schepers, Douglas Livingstone, Elliott Sprehn, Elliotte Harold, Eric Lawrence, Eric Uhrhane, Erik Arvidsson, Erik Dahlström, Feras Moussa, Gideon Cohn, Glenn Adams, Gorm Haug Eriksen, Gregory Terzian, Håkon Wium Lie, Hallvord R. M. Steen, Henri Sivonen, Hiroshige Hayashizaki, Huub Schaeks, Ian Clelland, Ian Davis, Ian Hickson, Ivan Herman, Jake Archibald, Jared Jacobs, Jarred Nicholls, Jeff Walden, Jens Lindström, Jim Deegan, Jim Ley, Joe Farro, Jonas Sicking, Julian Reschke, 송정기 (Jungkee Song), 呂康豪 (Kang-Hao Lu), Karl Dubost, Keith Yeung, 田村健人 (Kent TAMURA), Lachlan Hunt, Maciej Stachowiak, Magnus Kristiansen, Manish Goregaokar, Marc Hadley, Marcos Caceres, Mark Baker, Mark Birbeck, Mark Nottingham, Mark S. Miller, Martin Hassman, Mike Pennisi, Mohamed Zergaoui, Ms2ger, Noam Rosenthal, Odin Hørthe Omdal, Olli Pettay, Pawel Glowacki, Peter Michaux, Philip Jägenstedt, Philip Taylor, Rashika Jaggi, Robin Berjon, Rune F. Halvorsen, Ruud Steltenpool, Ryo Onodera, Sam Sneddon, Sergiu Dumitriu, Shivakumar Jagalur Matt, Sigbjørn Finne, Simon Pieters, Stewart Brodie, Sunava Dutta, Takeshi Kurosawa, Takeshi Yoshino, Thomas Roessler, Thomas Wisniewski, Tom Magliery, Travis Leithead, triple-underscore, Yaron Tausky, Yehuda Katz, Youenn Fablet,和 Zhenbin Xu 等人为该标准做出的贡献。

特别感谢首次实现 XMLHttpRequest 接口的微软员工,该接口首次通过 Windows Internet Explorer 浏览器广泛部署。

特别感谢 Ian Hickson 起草了最初版本的本规范,该规范最初在 HTML 标准(当时是 Web Applications 1.0)中。[HTML]

特别感谢 W3C SVG 工作组在 SVG 微型 DOM 中起草了原始的 ProgressEvent 类。

本标准由 Anne van KesterenAppleannevk@annevk.nl)撰写。

知识产权声明

版权所有 © WHATWG(Apple、Google、Mozilla、Microsoft)。本作品采用 Creative Commons Attribution 4.0 International License 进行许可。若部分内容已被纳入源代码,则源代码中的该部分根据 BSD 3-Clause License 许可。

这是现行标准。对专利审查版本感兴趣的用户应查看 现行标准审查草案

索引

本规范定义的术语

通过引用定义的术语

参考文献

规范性引用

[DOM]
Anne van Kesteren. DOM 标准. 现行标准. URL: https://dom.spec.whatwg.org/
[DOM-PARSING]
Travis Leithead. DOM 解析与序列化. URL: https://w3c.github.io/DOM-Parsing/
[ECMASCRIPT]
ECMAScript 语言规范. URL: https://tc39.es/ecma262/multipage/
[ENCODING]
Anne van Kesteren. 编码标准. 现行标准. URL: https://encoding.spec.whatwg.org/
[FETCH]
Anne van Kesteren. Fetch 标准. 现行标准. URL: https://fetch.spec.whatwg.org/
[FILEAPI]
Marijn Kruisselbrink. 文件 API. URL: https://w3c.github.io/FileAPI/
[HTML]
Anne van Kesteren 等. HTML 标准. 现行标准. URL: https://html.spec.whatwg.org/multipage/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra 标准. 现行标准. URL: https://infra.spec.whatwg.org/
[MIMESNIFF]
Gordon P. Hemsley. MIME 嗅探标准. 现行标准. URL: https://mimesniff.spec.whatwg.org/
[URL]
Anne van Kesteren. URL 标准. 现行标准. URL: https://url.spec.whatwg.org/
[WEBDRIVER-BIDI]
James Graham; Alex Rudenko; Maksim Sadym. WebDriver BiDi. URL: https://w3c.github.io/webdriver-bidi/
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL 标准. 现行 标准. URL: https://webidl.spec.whatwg.org/
[XML]
Tim Bray 等. 可扩展标记语言 (XML) 1.0 (第五版). 2008 年 11 月 26 日. REC. URL: https://www.w3.org/TR/xml/
[XML-NAMES]
Tim Bray 等. XML 名称空间 1.0 (第三版). 2009 年 12 月 8 日. REC. URL: https://www.w3.org/TR/xml-names/

IDL 索引

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestEventTarget : EventTarget {
  // event handlers
  attribute EventHandler onloadstart;
  attribute EventHandler onprogress;
  attribute EventHandler onabort;
  attribute EventHandler onerror;
  attribute EventHandler onload;
  attribute EventHandler ontimeout;
  attribute EventHandler onloadend;
};

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequestUpload : XMLHttpRequestEventTarget {
};

enum XMLHttpRequestResponseType {
  "",
  "arraybuffer",
  "blob",
  "document",
  "json",
  "text"
};

[Exposed=(Window,DedicatedWorker,SharedWorker)]
interface XMLHttpRequest : XMLHttpRequestEventTarget {
  constructor();

  // event handler
  attribute EventHandler onreadystatechange;

  // states
  const unsigned short UNSENT = 0;
  const unsigned short OPENED = 1;
  const unsigned short HEADERS_RECEIVED = 2;
  const unsigned short LOADING = 3;
  const unsigned short DONE = 4;
  readonly attribute unsigned short readyState;

  // request
  undefined open(ByteString method, USVString url);
  undefined open(ByteString method, USVString url, boolean async, optional USVString? username = null, optional USVString? password = null);
  undefined setRequestHeader(ByteString name, ByteString value);
           attribute unsigned long timeout;
           attribute boolean withCredentials;
  [SameObject] readonly attribute XMLHttpRequestUpload upload;
  undefined send(optional (Document or XMLHttpRequestBodyInit)? body = null);
  undefined abort();

  // response
  readonly attribute USVString responseURL;
  readonly attribute unsigned short status;
  readonly attribute ByteString statusText;
  ByteString? getResponseHeader(ByteString name);
  ByteString getAllResponseHeaders();
  undefined overrideMimeType(DOMString mime);
           attribute XMLHttpRequestResponseType responseType;
  readonly attribute any response;
  readonly attribute USVString responseText;
  [Exposed=Window] readonly attribute Document? responseXML;
};

typedef (File or USVString) FormDataEntryValue;

[Exposed=(Window,Worker)]
interface FormData {
  constructor(optional HTMLFormElement form, optional HTMLElement? submitter = null);

  undefined append(USVString name, USVString value);
  undefined append(USVString name, Blob blobValue, optional USVString filename);
  undefined delete(USVString name);
  FormDataEntryValue? get(USVString name);
  sequence<FormDataEntryValue> getAll(USVString name);
  boolean has(USVString name);
  undefined set(USVString name, USVString value);
  undefined set(USVString name, Blob blobValue, optional USVString filename);
  iterable<USVString, FormDataEntryValue>;
};

[Exposed=(Window,Worker)]
interface ProgressEvent : Event {
  constructor(DOMString type, optional ProgressEventInit eventInitDict = {});

  readonly attribute boolean lengthComputable;
  readonly attribute double loaded;
  readonly attribute double total;
};

dictionary ProgressEventInit : EventInit {
  boolean lengthComputable = false;
  double loaded = 0;
  double total = 0;
};

MDN

FormData/FormData

In all current engines.

Firefox4+Safari5+Chrome5+
Opera12+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari5+Chrome for Android?Android WebView3+Samsung Internet?Opera Mobile12+
MDN

FormData/append

In all current engines.

Firefox4+Safari5+Chrome5+
Opera12+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari5+Chrome for Android?Android WebView3+Samsung Internet?Opera Mobile12+
MDN

FormData/delete

In all current engines.

Firefox39+Safari11.1+Chrome50+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

FormData/get

In all current engines.

Firefox39+Safari11.1+Chrome50+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

FormData/getAll

In all current engines.

Firefox39+Safari11.1+Chrome50+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

FormData/has

In all current engines.

Firefox39+Safari11.1+Chrome50+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

FormData/set

In all current engines.

Firefox39+Safari11.1+Chrome50+
Opera?Edge79+
Edge (Legacy)18IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

FormData

In all current engines.

Firefox4+Safari5+Chrome5+
Opera12+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari5+Chrome for Android?Android WebView3+Samsung Internet?Opera Mobile12+
Node.js18.0.0+
MDN

ProgressEvent/ProgressEvent

In all current engines.

Firefox18+Safari6+Chrome16+
Opera12.1+Edge79+
Edge (Legacy)14+IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

ProgressEvent/lengthComputable

In all current engines.

Firefox3.5+Safari3.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

ProgressEvent/loaded

In all current engines.

Firefox3.5+Safari3.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

ProgressEvent/total

In all current engines.

Firefox3.5+Safari3.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

ProgressEvent

In all current engines.

Firefox3.5+Safari3.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/XMLHttpRequest

In all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/abort

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/abort_event

In all current engines.

Firefox3.5+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/abort_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/abort_event

In all current engines.

Firefox3.5+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/abort_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/error_event

In all current engines.

Firefox1+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/error_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/error_event

In all current engines.

Firefox1+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/error_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/getAllResponseHeaders

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/getResponseHeader

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/load_event

In all current engines.

Firefox1+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/load_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/load_event

In all current engines.

Firefox1+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/load_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/loadend_event

In all current engines.

Firefox5+Safari4+Chrome18+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/loadend_event

In all current engines.

Firefox5+Safari4+Chrome18+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/loadend_event

In all current engines.

Firefox5+Safari4+Chrome18+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/loadend_event

In all current engines.

Firefox5+Safari4+Chrome18+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/loadstart_event

In all current engines.

Firefox3.5+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/loadstart_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/loadstart_event

In all current engines.

Firefox3.5+Safari1.3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/loadstart_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/open

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/overrideMimeType

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE11
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/progress_event

In all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/progress_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/progress_event

In all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+

XMLHttpRequestUpload/progress_event

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/readyState

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/readystatechange_event

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/readystatechange_event

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera9+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/response

In all current engines.

Firefox6+Safari5.1+Chrome9+
Opera11.6+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView3+Samsung Internet?Opera Mobile12+
MDN

XMLHttpRequest/responseText

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/responseType

In all current engines.

Firefox6+Safari5.1+Chrome31+
Opera18+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android50+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile18+
MDN

XMLHttpRequest/responseURL

In all current engines.

Firefox32+Safari8+Chrome37+
Opera?Edge79+
Edge (Legacy)14+IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
MDN

XMLHttpRequest/responseXML

In all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/send

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/setRequestHeader

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/status

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequest/statusText

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/timeout

In all current engines.

Firefox12+Safari7+Chrome29+
Opera17+Edge79+
Edge (Legacy)12+IE8+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile18+
MDN

XMLHttpRequest/timeout_event

In all current engines.

Firefox12+Safari7+Chrome29+
Opera?Edge79+
Edge (Legacy)12+IE8+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile?

XMLHttpRequestUpload/timeout_event

In all current engines.

Firefox12+Safari7+Chrome29+
Opera?Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile?
MDN

XMLHttpRequest/timeout_event

In all current engines.

Firefox12+Safari7+Chrome29+
Opera?Edge79+
Edge (Legacy)12+IE8+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile?

XMLHttpRequestUpload/timeout_event

In all current engines.

Firefox12+Safari7+Chrome29+
Opera?Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile?
MDN

XMLHttpRequest/upload

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequest/withCredentials

In all current engines.

Firefox3.5+Safari4+Chrome3+
Opera12+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12+
MDN

XMLHttpRequest

In all current engines.

Firefox1+Safari1.2+Chrome1+
Opera8+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile10.1+
MDN

XMLHttpRequestEventTarget

In all current engines.

Firefox1+Safari1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+IE7+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
MDN

XMLHttpRequestUpload

In all current engines.

Firefox3.5+Safari4+Chrome2+
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+