Answers for "fetch api"

0

fetch

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));
Posted by: Guest on July-02-2020
34

fetch

fetch('path-to-the-resource-to-be-fetched')
  .then((response) => {
  
    // Code for handling the response
  })
  .catch((error) => {
  
    // Code for handling the error
  });
Posted by: Guest on June-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language