I have a form, the form is including 2 text inputs and 1 file upload input. Text inputs are working with AJAX. But the file upload is not working with ajax. If i don't use ajax, its working. So my app is completely working, but without ajax, the page has to refresh because its directly going to the php file, but i dont want that. I want to use AJAX. How can i use ajax for this form?
$("#form").submit(function(e) {
e.preventDefault();
$.ajax({
url: 'config.php',
type: 'POST',
data: $("#form").serialize(),
success: function () {
$(".upClass").html("Updated");
}
})
})
<form id="form" method="POST" enctype="multipart/form-data">
<div class="form-group">
<input type="text" class="form-control" name="site_title">
</div>
<div class="form-group">
<textarea class="form-control" name="site_description" ></textarea>
</div>
<div class="form-group">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary upClass">Update</button>
</div>
</form>
I dont share my config.php because its already working.