tcj*_*tcj 39 javascript ajax jquery
我有那个代码:
for (var i = 0; i < $total_files; i++) {
$.ajax({
type: 'POST',
url: 'uploading.php',
context: $(this),
dataType: 'json',
cache: false,
contentType: false,
processData: false,
data: data_string,
success: function(datas) {
//does something
},
error: function(e) {
alert('error, try again');
}
});
}
Run Code Online (Sandbox Code Playgroud)
它上传的图片非常好,但问题是我找不到逐个上传图片的方法,我试图将选项async设置为false但它冻结了网页浏览器,直到所有图片都上传不是我的想要,我想以某种方式模拟这个"async:false"选项来执行相同的操作但不冻结Web浏览器.
这该怎么做 ?
cha*_*tfl 66
您可以创建一个承诺数组,以便在解决所有承诺后,您可以运行您的all done代码.
var promises = [];
for (var i = 0; i < $total_files; i++){
/* $.ajax returns a promise*/
var request = $.ajax({
/* your ajax config*/
})
promises.push( request);
}
$.when.apply(null, promises).done(function(){
alert('All done')
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42784 次 |
| 最近记录: |