ajax multiple,jquery multiple Ajax request

This code snippet allows to drop multiple files dragged into a box. The filereader creates a blob of each file and then EACH file should be send to server using the ajax rq:

$.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

$.when($.ajax(???how to refer to THIS ajax call).done(function(){

//call this ajax for the next file again or use $.ajax(code).then()?

});

I am really sorry, but I do not know how to get it right.

Thanks for any suggestions!

h.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值