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

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

js fetch send json

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

get jsonp with fetch

fetchJsonp('/users.jsonp')
  .then(function(response) {
    return response.json()
  }).then(function(json) {
    console.log('parsed json', json)
  }).catch(function(ex) {
    console.log('parsing failed', ex)
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: toggle attribute jquery 
Javascript :: how to check if radio button is checked javascript 
Javascript :: js one line if 
Javascript :: sequelize get only one column 
Javascript :: add leading zeros javascript 
Javascript :: typescript class constructor default values 
Javascript :: get pods running on a node 
Javascript :: js image on canvas 
Javascript :: javascript get random array of integre in given range 
Javascript :: javascript delete first character from string 
Javascript :: set date input html using js 
Javascript :: the submitted data was not a file. check the encoding type on the form django react 
Javascript :: javascript html encode 
Javascript :: jquery switch class 
Javascript :: expo image picker 
Javascript :: router navigatebyurl 
Javascript :: setinterval vs settimeout js 
Javascript :: nestjs return error response 
Javascript :: Use History React Router v6 app 
Javascript :: moment day in range 
Javascript :: toggle hidden attribute javascript 
Javascript :: jwt token expire times 
Javascript :: find in array react 
Javascript :: how to find the last object in an array 
Javascript :: how to get current date in react js 
Javascript :: audio in react 
Javascript :: lottie react 
Javascript :: get id of first td jquery 
Javascript :: react onclick with event 
Javascript :: bootstrap in react 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =