Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fetch json post

(async () => {
  const rawResponse = await fetch('https://httpbin.org/post', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({a: 1, b: 'Textual content'})
  });
  const content = await rawResponse.json();

  console.log(content);
})();
Comment

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

json post fetch

fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
   body: JSON.stringify({
     // your expected POST request payload goes here
      title: "My post title",
      body: "My post content."
      })
})
  .then(res => res.json())
  .then(data => {
   // enter you logic when the fetch is successful
    console.log(data)
  })
  .catch(error => {
  // enter your logic for when there is an error (ex. error toast)
   console.log(error)
  })  
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 :: react get input value on button click functional component 
Javascript :: js array into object 
Javascript :: npm react router dom 
Javascript :: jest check buffer 
Javascript :: js stop scrolling event 
Javascript :: how to use ionicons in react 
Javascript :: web3 check if contract 
Javascript :: javascript how to sort nodes from dom 
Javascript :: scroll to top in react 
Javascript :: get all rooms socket.io 
Javascript :: connecting to mongodb using mongoose 
Javascript :: mysql get json value by key 
Javascript :: jquery element distance from top of window 
Javascript :: react-native-youtube-iframe android crash 
Javascript :: react native metro api level 30 
Javascript :: javascript how to push to an array while blindfolded 
Javascript :: datatables typeerror k is undefined 
Javascript :: date regex 
Javascript :: an image gallery is a set of images with corresponding remove buttons 
Javascript :: how to get greatest common divisor in javascript 
Javascript :: javascript group by sum array reduce 
Javascript :: remove a particular element from array 
Javascript :: ^(?:(+|00)d{1,3}[-s.])?(()?d{3,10}())?(?:[-s.)]d{2,7}([-s.]d{2,5})?([-s.]d{2})?)?$ 
Javascript :: adonisjs findorcreate 
Javascript :: how to shuffle an array in js 
Javascript :: emmet react self closing tags 
Javascript :: multi-stage Dockerfile for Node.js 
Javascript :: load js after ajax 
Javascript :: how to revers bulain in js 
Javascript :: create element javascript with class 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =