$('#tbFileList').find(":checkbox:checked").each(function(){
$.ajax({ url: "...", async: true, ... }); // 異步並發,無法保證順序
});
$.ajax({
async: false, // 瀏覽器主線程阻塞,按順序執行
success: function(){ ... }
});
缺點:阻塞 UI、Chrome 控制台警告「Synchronous XMLHttpRequest on the main thread is deprecated」,長請求導致頁面假死。
const checkboxes = $('#tbFileList').find(":checkbox:checked").get();
(async () => {
for (const cb of checkboxes) {
const filename = $(cb).parents(".ckc").find('#lblname').text();
const filepath = $(cb).parents(".ckc").find('#lblpath').text();
await $.ajax({ url: "...", data: {filename, filepath}, method: "POST" });
// 可選:更新 UI 進度
}
alert("全部完成");
})();
fetch。