首页 > 解决方案 > 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}`);
      }
    }); ```

标签: javascriptjsonpost

解决方案


推荐阅读