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?
Use the FormData
class in JavaScript:
var form = document.querySelector('form');
var data = new FormData(form);
axios.post('/example', data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.