Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript fetch api post

fetch('https://example.com/profile', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
  	'foo': 'bar'
  }),
})
  .then((res) => res.json())
  .then((data) => {
    // Do some stuff ...
  })
  .catch((err) => console.log(err));
Comment

fetch post

fetch("/echo/json/",
{
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    method: "POST",
    body: JSON.stringify({a: 1, b: 2})
})
.then(function(res){ console.log(res) })
.catch(function(res){ console.log(res) })
Comment

fetch post

fetch('https://httpbin.org/post', {
  method: 'POST',
  headers: {
    'Accept': 'application/json, text/plain, */*',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({a: 7, str: 'Some string: &=&'})
}).then(res => res.json())
  .then(res => console.log(res));
Comment

fetch post js

var myHeaders = new Headers();

var myInit = { method: 'POST',
               headers: myHeaders,
               mode: 'cors',
               cache: 'default' };

fetch('flowers.jpg',myInit)
.then(function(response) {
  return response.blob();
})
.then(function(myBlob) {
  var objectURL = URL.createObjectURL(myBlob);
  myImage.src = objectURL;
});

Comment

JavaScript POST request with Fetch API

const response = await fetch("https://reqbin.com/echo/post/json", {
method: 'POST',
headers: {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
},
body: `{
   "Id": 78912,
   "Customer": "Jason Sweet",
   "Quantity": 1,
   "Price": 18.00
  }`,
});

response.json().then(data => {
  console.log(data);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove undefined from array javascript 
Javascript :: jquery give control focus 
Javascript :: how to limit the number of items from an array in javascript 
Javascript :: javascript map return array with distinc values 
Javascript :: js check if object has property 
Javascript :: this.$set 
Javascript :: jquery cdn google 
Javascript :: react-router-dom v6 redirect 
Javascript :: how to check if user is typing discord js 
Javascript :: js convert string to script 
Javascript :: how to conver time format to 12 hours in javascript 
Javascript :: .map for object javscript 
Javascript :: how to change country code to country name in javascript 
Javascript :: play store rejected app due non-certified ads SDK 
Javascript :: how to kill a running node process 
Javascript :: generate random int js 
Javascript :: axios header accept language 
Javascript :: jquery get top position of element on scroll 
Javascript :: js get meta content 
Javascript :: jetbrains mono 
Javascript :: Uncaught ReferenceError: $localize is not defined angular 
Javascript :: jquery add disabled to id 
Javascript :: javascript get random array item 
Javascript :: javascript get data attribute of selected option 
Javascript :: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON 
Javascript :: wordpress add jquery script 
Javascript :: remove item from localstorage 
Javascript :: how to know which radio button is selected javascript 
Javascript :: smallest common multiple javascript 
Javascript :: how to create an anchor tag in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =