javascript - js中如何发出HTTP POST请求?
问题描述
我对此很陌生,我一直有错误“未捕获的语法错误:等待仅在异步函数中有效”
button.addEventListener('click', async => {
try {
const response = await fetch(
' https://student-challenge-api.herokuapp.com/students',
{
method: 'post',
json: true,
body: {
name: '',
last_name: ' '
},
}
);
console.log('Completed!', response);
} catch (err) {
console.error(`Error: ${err}`);
}
}); ```
解决方案
推荐阅读
- python - Hadoop 发现 2 个意外参数
- spartacus-storefront - 在 spartacus 3.x 版本上覆盖 UsersIdService.getUserId()
- flutter - 永久编辑全局变量的默认值
- django - 使用 django/laravel 从 sql 自动打印订单
- javascript - IOS 上的 React ( Next) Async / Await Bug
- html - 如何使用 ReactVirtualized 表从网站打印或复制/粘贴?
- logstash - 大字段值在 Kibana 仪表板中不可见
- excel - 单元格颜色变化时触发宏
- python - 熊猫数据框中的日期解析不正确
- task - 是否可以在异步 python 中暂停和重新启动任务?