如何使用 Axios 的“GET”请求和“POST”请求 onClick of button React

时间:2021-07-28 04:05:07

标签: axios

您好,我想调用 axios.get 请求,并通过单击按钮使用其中的数据在 axios.post 中使用。这是我现在的代码

const selectCarrier =  () => {
      return axios.get(`/load_details?id=${sessionStorage.loadId}`)
        .then((response) => {
          const result = response.data
          var infos = {
            bid_id: result["id"],
            agent_id: sessionStorage.id,
            user_type: sessionStorage.type,
            name: this.state.carrier,
            offer: null,
          }
          
         
            axios.post('/bids/carrier/accept', infos)
         

          
        })
    

按钮代码

 <Button onClick={() => { selectCarrier(); this.setState({ bookedbyopen: false, book: this.state.carrier }) }}>Confirm</Button>

我得到的错误是内部服务器 500 错误,在终端上显示“AttributeError: 'NoneType' object has no attribute 'accepted'”。 post方法在这个函数之外工作,我已经测试过了。 get 方法也同样有效,并且不返回任何“NoneType”对象。只有当我在同一个函数中使用它们时,但我需要这样做但不知道如何。谢谢!

0 个答案:

没有答案