I'm trying to upload a image to my server using a POST form and AJAX. But everytime I submit the form, my AJAX returns an undefined
in my error box. This is the Ajax function I'm talking about:
$('.register_submit').click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "./functions/register.php",
data: new FormData(this),
contentType: false,
processData: false,
success : function(data){
if (data.code == "200"){
window.location.replace("./?page=home");
} else {
$(".display-error").html("<ul>"+data.msg+"</ul>");
$(".display-error").css("display","block");
}
}
});
});
and my form:
<form class="addCar_form" data-toggle="validator" method="post" enctype="multipart/form-data" >
<input type="file" class="form-control productimages" id="images" name="images[]" onchange="preview_images();" multiple/>
<input type="submit" name="addCar_submit" value="Auto toevoegen" class="btn btn-default button addCar_submit">
</form>
Please do not mark this question as a duplicate, as I've been reading about ajax and it being asynchronous in other topics but I'm really not getting it from these answers. Anyone who sees what I'm doing wrong?