Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fetch post image mdn

const data = { username: 'example' };

fetch('https://example.com/profile', {
  method: 'POST', // or 'PUT'
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
  console.log('Success:', data);
})
.catch((error) => {
  console.error('Error:', error);
});
Comment

fetch post image mdn

const formData = new FormData();
const 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())
.then(result => {
  console.log('Success:', result);
})
.catch(error => {
  console.error('Error:', error);
});
Comment

fetch post image mdn

const formData = new FormData();
const photos = document.querySelector('input[type="file"][multiple]');

formData.append('title', 'My Vegas Vacation');
for (let i = 0; i < photos.files.length; i++) {
  formData.append(`photos_${i}`, photos.files[i]);
}

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

PREVIOUS NEXT
Code Example
Javascript :: convert negative number to positive in javascript 
Javascript :: javascript loop over classes 
Javascript :: get attribute value jquery 
Javascript :: check when keyup an input from a specific form jquery 
Javascript :: capitalize in javascript 
Javascript :: array has object with property js 
Javascript :: how to connect metamask wallet with js 
Javascript :: javascript is variable number or string 
Javascript :: javascript get bit 
Javascript :: js find object from value in array 
Javascript :: js switch case greater than 
Javascript :: jest check array of string 
Javascript :: js array to object with keys 
Javascript :: gatsby-plugin-create-client-paths 
Javascript :: javascript get line number of error 
Javascript :: js remove from array by value 
Javascript :: angular lifecycle hooks 
Javascript :: new date with date + 1 
Javascript :: get value from another textinput and set is to another using jquery 
Javascript :: async fetch api call 
Javascript :: hide div js 
Javascript :: check if function exists javascript 
Javascript :: how to read write object to localStorage in js 
Javascript :: vue watch deep property 
Javascript :: javascript remove period from end of string 
Javascript :: how to make react router Link active 
Javascript :: mongoose connect to URL of atals 
Javascript :: js window redirect 
Javascript :: disable right click using jquery 
Javascript :: browserrouter react 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =