该法典允许将多份被拖入箱子的档案。 存档器制作每个档案的书目,然后使用Ajax rq向服务器发送EACH文件:
$.each( e.dataTransfer.files, function(index, file){
var fileReader = new FileReader();
//..generate BLOB from file
fileReader.onloadend = (function(file) {
return function(e) {
uploadfilelist.append( <li> + file.fileName + </li> );
//send every single file to server
var destfoldername=CURRENTPATH;
var uploadfilename=file.fileName;
var fd = new FormData();
fd.append("param1", destfoldername);
fd.append("param2", uploadfilename);
fd.append("param3", blob);
$.ajax({
type:"POST",
url:"url",
data:fd,
contentType: false,
processData: false,
beforeSend:function (xhr){
//custom headers
},
success: function(data, textStatus, jqXHR){
},
complete: function(jqXHR){
alert("State after complete: " + jqXHR.statusText);
}
});
};
})(file);
fileReader.readAsBinaryString(file);
}
PROBLEM: the server internal crashes when receiving a next blob while not having processed the former one.
I found another Post discussing this: How to make all AJAX calls sequential? A "sequential" Request using async:false is not an option, it would block a whole lot of other things..
SOLUTION: ??? Call ajax forfile1, when call is done, call ajax for file2, ...call ajax for file-n
I would really like to use JQ Deferred (http://api.jquery.com/category/deferred-object/) e.g. as described here: http://api.jquery.com/jQuery.when/
$.when($.ajax(???how to refer to THIS ajax call).done(function(){
//call this ajax for the next file again or use $.ajax(code).then()?
});
我确实感到担忧,但我不知道如何正确。
Thanks for any suggestions! h.