“Ambil di JS” Kode Jawaban

node js fetch

const fetch = require('node-fetch');	//npm install node-fetch

fetch('https://httpbin.org/post', {
  method: 'POST',
  body: 'a=1'
})
  .then(res => res.json())
  .then(json => {
	// Do something...
  })
  .catch(err => console.log(err));
garzj

js mengambil pos json

//Obj of data to send in future like a dummyDb
const data = { username: 'example' };

//POST request with body equal on data in JSON format
fetch('https://example.com/profile', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(data),
})
.then((response) => response.json())
//Then with the data from the response in JSON...
.then((data) => {
  console.log('Success:', data);
})
//Then with the error genereted...
.catch((error) => {
  console.error('Error:', error);
});

//																		Yeah
Sticky Pingu

JavaScript Fetch API Posting

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));
garzj

Ambil di JS

fetch('http://example.com/songs')
	.then(response => response.json())
	.then(data => console.log(data))
	.catch(err => console.error(err));
Bewildered Booby

Fetch JS

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);
});
Lively Ladybird

Fetch API JavaScript

fetch('http://example.com/movies.json')
  .then((response) => {
    return response.json();
  })
  .then((myJson) => {
    console.log(myJson);
  });
Gleaming Gemsbok

Jawaban yang mirip dengan “Ambil di JS”

Pertanyaan yang mirip dengan “Ambil di JS”

Lebih banyak jawaban terkait untuk “Ambil di JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya