【问题标题】:i'm using axios post request in Formik,and return me 400 error我在 Formik 中使用 axios 发布请求,并返回 400 错误
【发布时间】:2021-10-06 18:17:09
【问题描述】:

enter image description here 请看一下img,我尝试使用它,但它的效果不好,我不明白为什么

<Formik        
initialValues={{email: "", password: "", firstname: "",
           lastname: "", passwordConfirm: ""}}


onSubmit={(values, {setSubmitting}) => {
        console.log(values);

        // Send a POST r`enter code here`equest
        axios.post('http://212.42.212.29:3001/auth/register', values, {
            "headers": {
                "content-type": "application/json",
            }
        }).then(function (response) {
            console.log(response);
        }).catch(function (error) {
                console.log(error.response);
            });

    }}
  
>

【问题讨论】:

  • 400 - 错误请求。确保您提供了正确的端点并检查后端是否正在运行

标签: javascript reactjs api axios formik


【解决方案1】:

我的错误是在 Formik 中,我错误地写了值名称

   <Formik 
     initialValues={{email: "", password: "", firstname: "", lastname: "", 
       passwordConfirm: ""}}
     >

**应该是**

   <Formik 
    initialValues={
          {email: "", 
           password: "", 
         **firstName: "",** 
         **lastName:""**, 
     passwordConfirm: ""}}
   >

【讨论】:

    猜你喜欢
    • 2020-11-19
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2021-05-21
    • 1970-01-01
    • 2019-12-03
    相关资源
    最近更新 更多