set()
方法在
FormData
interface sets a new value for an existing key inside a
FormData
object, or adds the key/value if it does not already exist.
差异在
set()
and
FormData.append
is that if the specified key does already exist,
set()
will overwrite all existing values with the new one, whereas
FormData.append
will append the new value onto the end of the existing set of values.
注意 : This method is available in Web 工作者 .
There are two versions of this method: a two and a three parameter version:
formData.set(name, value); formData.set(name, value, filename);
名称
value
.
value
USVString
or
Blob
(including subclasses such as
File
). If none of these are specified the value is converted to a string.
filename
可选
USVString
),当
Blob
or
File
is passed as the second parameter. The default filename for
Blob
objects is "blob". The default filename for
File
objects is the file's filename.
注意:
If you specify a
Blob
as the data to append to the
FormData
object, the filename that will be reported to the server in the "Content-Disposition" header used to vary from browser to browser.
The following line creates an empty
FormData
对象:
var formData = new FormData(); // Currently empty
You can set key/value pairs on this using
FormData.set
:
formData.set('username', 'Chris');
formData.set('userpic', myFileInput.files[0], 'chris.jpg');
If the sent value is different than String or Blob it will be automatically converted to String:
formData.set('name', 72);
formData.get('name'); // "72"
| 规范 | 状态 | 注释 |
|---|---|---|
|
XMLHttpRequest
The definition of 'set()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
set
|
Chrome 50 | Edge 18 | Firefox 39 | IE No | Opera 37 | Safari 11 | WebView Android 50 | Chrome Android 50 | Firefox Android 39 | Opera Android 37 | Safari iOS 11 | Samsung Internet Android 5.0 |
完整支持
不支持
FormData