JSFiddle - React, Tailwind, and code Playground
by cihkem
HTML
<form id="contact_img" enctype="multipart/form-data" method="post">
<input id="contact_image" name="contact_image" type="file" class="file">
<input type="text" class="form-control" name="testtest" id="testtest" required>
<button type="submit" class="btn-default">Save</button>
</form>
JavaScript
$(document).ready(function(e) {
$("#contact_img").on('submit', function(e){
e.preventDefault();
var form = new FormData(e.target)
console.log(form.get('contact_image'))
$.ajax({
url: "/echo/html",
data : form,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: function (data) {
alert(data);
},
type:'POST'
});
});})