“JavaScript mengambil data formulir posting” Kode Jawaban

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

JavaScript mengambil data formulir posting

javascript fetch post form data with headers , in reactjs
--------------------------------
let formData = new FormData();
formData.append('data', 'formdata');
formData.append('data', 'formdata');

export const getData = async () => {
    await fetch('----url------', {
        method: 'POST',
        headers: {
            Authorization: 'Basic -------token----------',
        },
        body: formData
    }).then(response => response.json())
        .then(data => {
            console.log(data);
        })
}
ASHABB

mengirim data formulir dengan ambil menggunakan 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

Kirim Data Formulir Menggunakan Fetch

async function sendFormData()
 {

 const myData = document.getElementById("myData");
const formData = new FormData(myData);

	const obj= Object.fromEntries(formData);

const res = await fetch('/test', {method:'POST', body: JSON.stringify(obj), headers:{'Content-type': 'application/json; charset=UTF-8'}});
const response = await res.json();

console.log(response["a"]);

 }
Javasper

Jawaban yang mirip dengan “JavaScript mengambil data formulir posting”

Pertanyaan yang mirip dengan “JavaScript mengambil data formulir posting”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya