Home > Back-end >  why i am getting this error while i run react app and click submit in form
why i am getting this error while i run react app and click submit in form

Time:10-06

App.js

import React from "react";
import { useState } from "react";
import axios from 'axios'
const App=()=>{
  const [data,Setdata]=useState({name:'',password:''});
  
  const Handler=e=>{Setdata({...data,[e.target.name]:e.target.value})}
  const submitHandler=e=>{
    e.preventDefault();
    axios.post('https://charming-league-352616-default-rtdb.firebaseio.com/register.json',data).then(()=>alert("submittted successfully"))
  


  }
  return(
    <div>
      <center>
      <form onSubmit={submitHandler}>
      <label style={{'color':'red'}}>Name:</label><br/>
      <input type="text" name="name"onChange={Handler}/><br/>
      <label style={{'color':'pink'}}>Passoword</label><br/>
      <input type="password" password="age" onChange={Handler}></input><br/>
      <input type="submit" value="submit"></input>
</form>
</center>
    </div>
  )
}
export default App;

Error

  1. `POST https://charming-league-352616-default-rtdb.firebaseio.com/register.json 400 (Bad Request)`
    
  2. Uncaught (in promise) AxiosError {message: 'Request failed with status code 400', name: ' 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}

CodePudding user response:

Seems Submit works fine and the problem Detects in your api request

Try check your request in PostMan

CodePudding user response:

something wrong on your api req

  • Related