这篇翻译不完整。请帮忙从英语翻译这篇文章

XMLHttpRequest.responseType 属性是一个枚举类型的属性,返回响应数据的类型。它允许我们手动的设置返回数据的类型。如果我们将它设置为一个空字符串,它将使用默认的"text"类型。

在工作环境(Work Environment)中将responseType的值设置为"document"通常会被忽略. 当将responseType设置为一个特定的类型时,你需要确保服务器所返回的类型和你所设置的返回值类型是兼容的。那么如果两者类型不兼容呢?恭喜你,你会发现服务器返回的数据变成了null,即使服务器返回了数据。还有一个要注意的是,给一个同步请求设置responseType会抛出一个InvalidAccessError 的异常。

responseType支持以下几种值:

描述
"" responseType 设为空字符串与设置为"text"相同, 是默认类型 (实际上是 DOMString)。
"arraybuffer" response 是一个包含二进制数据的 JavaScript ArrayBuffer
"blob" response 是一个包含二进制数据的 Blob 对象 。
"document" response 是一个 HTML DocumentXML XMLDocument ,这取决于接收到的数据的 MIME 类型。请参阅 HTML in XMLHttpRequest 以了解使用 XHR 获取 HTML 内容的更多信息。
"json" response 是一个 JavaScript 对象。这个对象是通过将接收到的数据类型视为 JSON 解析得到的。
"text" response 是包含在 DOMString 对象中的文本。
"moz-chunked-arraybuffer"

"arraybuffer"相似,但是数据会被接收到一个流中。使用此响应类型时,响应中的值仅在 progress 事件的处理程序中可用,并且只包含上一次响应 progress 事件以后收到的数据,而不是自请求发送以来收到的所有数据。

在 progress 事件处理时访问 response 将返回到目前为止收到的数据。在 progress 事件处理程序之外访问, response 的值会始终为 null

"ms-stream" response 是下载流的一部分;此响应类型仅允许下载请求,并且仅受Internet Explorer支持。

规范

规范 状态 注释
XMLHttpRequest Living Standard WHATWG living standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 31Edge Full support 12Firefox Full support 6IE Full support 10Opera Full support 18Safari Full support 7WebView Android Full support 55Chrome Android Full support 55Edge Mobile Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support 6.0
arraybufferChrome Full support 10Edge Full support YesFirefox Full support 6IE Full support 10Opera Full support 18Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
blobChrome Full support 19Edge Full support YesFirefox Full support 6IE Full support 10Opera Full support 12Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
documentChrome Full support 18Edge Full support YesFirefox Full support 11IE Full support 10Opera No support NoSafari Full support 6.1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
jsonChrome Full support 31Edge No support NoFirefox Full support 10IE No support NoOpera Full support 17
Full support 17
No support 12 — 16
Safari Full support 6.1WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 50Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
moz-blobChrome No support NoEdge No support NoFirefox No support 12 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

了解更多

文档标签和贡献者

此页面的贡献者: urain39, scottxu, CodingSherlock, breakair, xgqfrms-GitHub
最后编辑者: urain39,