请求:formData() 方法
语法
js
formData()
参数
无。
返回值
示例
js
const formData = new FormData();
const fileField = document.querySelector('input[type="file"]');
formData.append("username", "abc123");
formData.append("avatar", fileField.files[0]);
const request = new Request("/myEndpoint", {
method: "POST",
body: formData,
});
request.formData().then((data) => {
// do something with the formdata sent in the request
});
规范
规范 |
---|
Fetch 标准 # ref-for-dom-body-formdata① |
浏览器兼容性
BCD 表格仅在浏览器中加载