Hi I made an Ajax upload form and it can handle multiple files.
I use XMLHttpRequest(); to send the request but what I'm really trying to do is to make the form send one file at a time (send the first file then wait to upload.php response then send the next file);
I have been trying this but didn't work:
function _(el){
return document.getElementById(el);
}
function uploadFile(){
var file = _("file").files;
var formdata= new FormData();
var ajax;
for(var i=0;i<file.length;i++){
formdata.append("file[]",file[i]);
ajax= new XMLHttpRequest();
ajax.upload.addEventListener("progress",progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler,false);
ajax.open("POST","Upload.php");
ajax.send(formdata);
}
}
function progressHandler(event){
_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
var percent= (event.loaded / event.total) * 100;
_("progressBar").value = Math.round(percent);
_("status").innerHTML = Math.round(percent)+"% uploading... please wait";
}
function completeHandler(event){
_("status").innerHTML = event.target.responseText;
_("progressBar").value = 0;
}
If any one can help?