I am trying to send both an image file and a array via my AJAX request to my PHP script, but either the array or the image file dosen't show up. I have located the problem being the lines, that you have to add to your AJAX when you are dealing with files.
contentType: false, processData: false,
If these two lines are added the array arrives at PHP script empty. What can I do differently? :)
My AJAX:
$('#createMember').on('submit', function(event){
event.preventDefault();
$("#LoadingIcon").show();
var form_data = $(this).serialize();
$.ajax({
url:"scripts/createMember.php",
method:"POST",
data:form_data,
cache: false,
contentType: false,
processData: false,
success:function(data)
{
$.notify({
title: '<strong>Created!</strong><br>',
message: 'Member is now created!'
});
$("#LoadingIcon").fadeOut(200);
});
});
My HTML
<form method="post" id="opretMedlem" enctype="multipart/form-data">
<input type="text" name="info[name]" class="form-control1 info" />
<input type="text" name="info[age]" class="form-control1 info" />
<input type="file" name="info[image]" class="form-control1 info" />
<input type="submit" name="submit" class="btn btn-info" value="Create member" />
</form>