📜  fetch API javascript sintax - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:02.543000             🧑  作者: Mango

代码示例1
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);
});