How do I append imageList[] array to FormData?
<form id="myform" method="POST" enctype="multipart/form-data">
<input id="imageupload" type="file" name="file[]" onchange="preview_image()"
multiple/>
<input id="send" type="submit" name="submit" value="Upload" />
<script>
function preview_image() {
var imagesArray = event.target.files;
var imageList = [];
var total_file=document.getElementById("imageupload").files.length;
for(var i=0;i<total_file;i++)
{
$('#demo').append("<img id='pre' alt='image'
src='"+URL.createObjectURL(imagesArray[i])+"'><button
id='del2'>Delete</button>");
imageList.push(imagesArray[i]);
}
window.imageList = imageList;
}
$(document).ready(function(){
$("#myform").on('submit',function(event){
event.preventDefault();
var formdata = new FormData();
formdata.append(imageList[]);
$.ajax({
url:'upload.php',
type: 'POST',
contentType: false,
processData: false,
data: formdata,
success : function(data){
}
});
});
});
</script>
I have created a var imageList array so that I could manipulate the array because is read-only. I would like to send the files from my imageList array using AJAX which is using FormData() .