MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

FormData

翻譯不完整。請協助 翻譯此英文文件

FormData 介面提供了一個簡單的方式來建立表單欄位與其值的名值對(key/value)集合,還能方便的使用 XMLHttpRequest.send() 方法來送出表單資料。如果 <form> 元素的 enctype 屬性(attribute)值為 multipart/form-data 編碼,則 FormData 物件也會採用與表單相同的格式。

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()).

註:此特性適用於 Web Workers

建構式

FormData()
建立一個新的 FormData object。

方法

FormData.append()
追加新的值到該 FormData object 已有的對應鍵上;若該鍵尚未建立,則追加一個新的鍵。
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/value pair.
FormData.keys()
Returns an iterator allowing to go through all keys f 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 of the key/value pairs contained in this object.

規範

Specification Status Comment
XMLHttpRequest
The definition of 'FormData' in that specification.
Living Standard FormData defined in XHR spec

瀏覽器相容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Edge Opera Safari
Basic support 7.0 (Yes) 4.0 (2.0)[1] 10 (Yes) 12 5
append with filename (Yes) No support 22.0 (22.0) ? ? (Yes) ?
delete(), get(), getAll(), has(), set() 50.0 No support 39.0 (39.0) No support ? (Yes) No support
entries(), keys(), values(), and support of for...of 50.0 No support 44.0 (44.0) ? ? (Yes) No support
Available in web workers (Yes) (Yes) 39.0 (39.0) No support ? (Yes) No support
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support 3.0[2] (Yes)[2] (Yes) 4.0 (2.0)[1] 1.0.1 ? 12 ? (Yes)
append with filename ? (Yes) No support 22.0 (22.0) 1.2 ? ? ? (Yes)
delete(), get(), getAll(), has(), set() (Yes) 50.0 No support No support No support No support No support No support 50.0
entries(), keys(), values(), and support of for...of ? 50.0 No support 44.0 (44.0) 2.5 ? ? ? 50.0
Available in web workers (Yes) (Yes) (Yes) (Yes) (Yes) No support (Yes) No support (Yes)

[1] Prior to Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), if you specified a Blob as the data to append to the object, the filename reported in the "Content-Disposition" HTTP header was an empty string; this resulted in errors being reported by some servers. Starting from Gecko 7.0, the filename "blob" is sent.

[2] XHR in Android 4.0 sends empty content for FormData with blob.

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo, teoli, Shiyou, ziyunfei
 最近更新: jackblackevo,