“mengambil” Kode Jawaban

mengambil

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

mengambil

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

mengambil

//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);
});

//
Creepy Gábor

mengambil

const options = {method: 'GET', headers: {Accept: 'application/json'}};

fetch('https://api.test.com/data/id', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
ofroog

mengambil

const fetch = require('node-fetch');

    let response = await fetch(`your url paste here`, {
      headers: {
        Authorization: `Token ${API_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
      method: 'POST',
    });
    const results = await response.json();
    console.log("======> :: results", results);
abhi

mengambil

var formData = new FormData();
var 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())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
Panicky Panda

mengambil

GET /orgs/octokit/repos
Anxious Ant

Jawaban yang mirip dengan “mengambil”

Pertanyaan yang mirip dengan “mengambil”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya