FormData - Web APIs 编辑
The FormData
interface provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send()
method. It uses the same format a form would use if the encoding type were set to "multipart/form-data"
.
You can also pass it directly to the URLSearchParams
constructor if you want to generate query parameters in the way a <form>
would do if it were using simple GET
submission.
An object implementing FormData
can directly be used in a for...of
structure, instead of entries()
: for (var p of myFormData)
is equivalent to for (var p of myFormData.entries())
.
Note: This feature is available in Web Workers.
Constructor
FormData()
- Creates a new
FormData
object.
Methods
FormData.append()
- Appends a new value onto an existing key inside a
FormData
object, or adds the key if it does not already exist. FormData.delete()
- Deletes a key/value pair from a
FormData
object. FormData.entries()
- Returns an
iterator
allowing to go through all key/value pairs contained in this object. FormData.get()
- Returns the first value associated with a given key from within a
FormData
object. FormData.getAll()
- Returns an array of all the values associated with a given key from within a
FormData
. FormData.has()
- Returns a boolean stating whether a
FormData
object contains a certain key. FormData.keys()
- Returns an
iterator
allowing to go through all keys of the key/value pairs contained in this object. FormData.set()
- Sets a new value for an existing key inside a
FormData
object, or adds the key/value if it does not already exist. FormData.values()
- Returns an
iterator
allowing to go through all values contained in this object.
Specifications
Specification | Status | Comment |
---|---|---|
XMLHttpRequest The definition of 'FormData' in that specification. | Living Standard | FormData defined in XHR spec |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论