📜  javascript fetch api post - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:53.105000             🧑  作者: Mango

代码示例6
var formData = new FormData();
var fileField = document.querySelector("input[type='file']");

formData.append('username', 'abc123');
formData.append('avatar', fileField.files[0]);

fetch('https://example.com/profile/avatar', {
  method: 'PUT',
  body: formData
})
.then(response => response.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));