翻译正在进行中。

FormData 接口提供了一种表示表单数据的键值对的构造方式,经过它的数据可以使用 XMLHttpRequest.send() 方法送出,本接口和此方法都相当简单直接。如果送出时的编码类型被设为 "multipart/form-data",它会使用和表单一样的格式。

如果你想构建一个简单的GET请求,并且通过<form>的形式带有查询参数,可以将它直接传递给URLSearchParams

实现了 FormData 接口的对象可以直接在for...of结构中使用,而不需要调用entries()for (var p of myFormData) 的作用和 for (var p of myFormData.entries()) 是相同的。

注意:此特性可用于 Web Workers

构造函数

FormData()
创建一个新的 FormData 对象。

方法

FormData.append()
向 FormData 中添加新的属性值,FormData 对应的属性值存在也不会覆盖原值,而是新增一个值,如果属性不存在则新增一项属性值。
FormData.delete()
从 FormData 对象里面删除一个键值对。
FormData.entries()
返回一个包含所有键值对的iterator对象。
FormData.get()
返回在 FormData 对象中与给定键关联的第一个值。
FormData.getAll()
返回一个包含 FormData 对象中与给定键关联的所有值的数组。
FormData.has()
返回一个布尔值表明 FormData 对象是否包含某些键。
FormData.keys()
返回一个包含所有键的iterator对象。
FormData.set()
给 FormData 设置属性值,如果FormData 对应的属性值存在则覆盖原值,否则新增一项属性值。
FormData.values()
返回一个包含所有值的iterator对象。

规范

规范 状态 备注
XMLHttpRequest
FormData
Living Standard FormData defined in XHR spec

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
FormDataChrome Full support 7Edge Full support YesFirefox Full support 4
Notes
Full support 4
Notes
Notes Prior to Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
IE Full support 10Opera Full support 12Safari Full support 5WebView Android Full support Yes
Notes
Full support Yes
Notes
Notes XHR in Android 4.0 sends empty content for FormData with blob.
Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support 12Safari iOS Full support YesSamsung Internet Android Full support Yes
FormData() constructorChrome Full support 7Edge Full support YesFirefox Full support 4IE Full support 10Opera Full support 12Safari Full support 5WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support 12Safari iOS ? Samsung Internet Android ?
appendChrome Full support 7Edge Full support 12Firefox Full support 4
Notes
Full support 4
Notes
Notes Prior to Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
IE Full support 10
Notes
Full support 10
Notes
Notes With the "Include local directory pass when uploading files to a server" option enabled, IE will change the filename inside the Blob on the fly. To have direct control of the sent filename, the developer should send the filename as the third parameter value, i.e. formData.append(name, value, filename).
Opera Full support 12Safari Full support 5WebView Android Full support 3
Notes
Full support 3
Notes
Notes XHR in Android 4.0 sends empty content for FormData with blob.
Chrome Android Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes Prior to Firefox 7, specifying a Blob as the data to append to the object, the filename reported in the Content-Disposition HTTP header was an empty string, resulting in errors on some servers. Starting with Firefox 7, the filename blob is sent.
Opera Android Full support 12Safari iOS Full support YesSamsung Internet Android Full support Yes
deleteChrome Full support 50Edge Full support 18Firefox Full support 39IE No support NoOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support 50Firefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
getChrome Full support 50Edge Full support 18Firefox Full support 39IE No support NoOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support 50Firefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
getAllChrome Full support 50Edge Full support 18Firefox Full support 39IE No support NoOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support 50Firefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
hasChrome Full support 50Edge Full support 18Firefox Full support 39IE No support NoOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support 50Firefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
setChrome Full support 50Edge Full support 18Firefox Full support 39IE No support NoOpera No support NoSafari Full support 11WebView Android Full support YesChrome Android Full support 50Firefox Android Full support YesOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
entriesChrome Full support 50Edge Full support 18Firefox Full support 44IE No support NoOpera Full support YesSafari Full support 11WebView Android ? Chrome Android Full support 50Firefox Android Full support 44Opera Android Full support YesSafari iOS ? Samsung Internet Android ?
keysChrome Full support 50Edge Full support 18Firefox Full support 44IE ? Opera Full support YesSafari Full support 11WebView Android ? Chrome Android Full support 50Firefox Android Full support 44Opera Android ? Safari iOS ? Samsung Internet Android ?
valuesChrome Full support 50Edge Full support 18Firefox Full support 44IE ? Opera ? Safari Full support 11WebView Android ? Chrome Android Full support 50Firefox Android Full support 44Opera Android ? Safari iOS ? Samsung Internet Android ?
Support of for...ofChrome Full support 50Edge No support NoFirefox Full support 44IE ? Opera ? Safari Full support 11WebView Android ? Chrome Android Full support 50Firefox Android Full support 44Opera Android ? Safari iOS ? Samsung Internet Android ?
Available in workersChrome Full support YesEdge Full support YesFirefox Full support 39IE No support NoOpera Full support YesSafari No support NoWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

参见

文档标签和贡献者

标签: 
最后编辑者: JiHPeng,