📜  获取 js - Javascript 代码示例

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

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