I came across this simple js ajax download code (it seems that jquery $.post doesn't work with HTML5 for some reason)
var fd = new FormData(); fd.append("file", document.getElementById('file').files[0]); //var fd = document.getElementById('form1').getFormData(); var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "Upload.php"); xhr.send(fd);
But I have two questions,
- What does this line mean after the
FormData object?
fd.append("file", document.getElementById('file').files[0]);
Why do I need an identifier? Is it possible to use jquery append() something with $('input[type=file]') ?
- This ajax is only for uploading a single file, how can I change it to upload multiple files?
source share