axios send post data
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});
axios send post data
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
headers: {'Authorization': 'Bearer ...'}
});
how to make a post request from axios
import axios from 'axios';
async makeRequest() {
try {
const response = await axios.post('your_request_url_here', {
// Enter your body parameters here
});
}
catch(e) {
// Handle your error here
}
}
// Axios returns a promise and hence you can use .then(), .catch for error
// handling if you don't want to use async/await(use try/catch for error
// handling)
how to use post method axios
const handleClick = async () => {
let fd = new FormData();
fd.append("name", name);
fd.append("password", password);
const rep = await axios
.post("http://localhost/php/api/students/create.php", fd)
.catch((err) => {
console.log(err, "axios error");
});
console.log(rep.data);
};
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us