2014-03-14 57 views
0

這裏我使用ajax each loop。但回調錯誤。回調成功或進度不適用於每個請求。首先,第二個callabacks被摺疊。ajax循環回調方法不適用於每個請求

entries.forEach(function (entry) { 
    var request = $.ajax({ 
     type: "POST", 
     url: 'base64upload', 
     data: { 'value': base64, 'filename': entry.filename, 'zipname': zipName[0], 'fileCount': fileCount, 'image_title': entry.filename }, 
     cache: false, 
     success: function (data) { 
      $("#" + barid).css("width", "100%"); 
      complete++; 
      console.log("success=" + barid); 
     }, 
     progress: function (evt) { 
      if (evt.lengthComputable) { 
       $("#" + barid).css("width", parseInt((evt.loaded/evt.total * 100), 10) + "%"); 
       console.log("progress=" + barid); 
      } 
     } 

    }); 

}); 

回答

0

您可以使用Ajax隊列做到這一點,請在這裏看到完整的文檔

$.ajaxq ("MyQueue", { 
        type: "POST", 
        url: 'base64upload', 
        data: {'value':base64, 'filename': entry.filename, 'zipname':zipName[0], 'fileCount': fileCount,'image_title':entry.filename}, 
        cache:false, 

       success: function(data) 
             { 
        $("#"+barid).css("width","100%"); 
        complete++; 
        console.log("success="+barid); 

             }, 
       progress: function(evt) { 
        if (evt.lengthComputable) { 
         $("#"+barid).css("width",parseInt((evt.loaded/evt.total * 100), 10) + "%"); 
         console.log("progress="+barid); 
         } 
        } 

       }); 

http://foliotek.github.io/AjaxQ/

+0

我想這對於找出所有的請求都完成後,我問它的每reques正確觸發 – user3331175