Just wondering if it's possible to serialize data from a Html form element and then post the data using a post request with Axios.
Here is the code that shows the event that is fired when a button click occurs to submit the post.
function form_submission(e)
{
var data = document.getElementById('venueForm');
axios.post('/venue/', {
})
.then (function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
Here is the html which shows how the data is selected
<form method="POST" action="http://core-site.test/venue/{{$venue->slug_field}}" accept-charset="UTF-8" id="venueForm">
Is serializing an option or do I have to set each value manually?
To Use Axios POST Request to Send Form Data in ReactJS First Of all, make a variable named bodyFormData with FormData(). Then You can simply append your form data in bodyFormData just like this: bodyFormData. append('userName', 'milan'); and then you can simply use this bodyFormData in your axios post request data.
Sending a PUT Request with Axios The simplest way to make the PUT call is to simply use the put() function of the axios instance, and supply the body of that request in the form of a JavaScript object: const res = await axios. put('/api/article/123', { title: 'Making PUT Requests with Axios', status: 'published' });
To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.
Use the FormData
class in JavaScript:
var form = document.querySelector('form');
var data = new FormData(form);
axios.post('/example', data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With