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
-
`POST https://charming-league-352616-default-rtdb.firebaseio.com/register.json 400 (Bad Request)`
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