我正在运行一个将表行从一个表移动到另一个表并将其存储到数据库的函数。我正在运行此异步,但最终导致行以错误的顺序存储。基本上它是如此之快,所以即使jQuery每个都以正确的顺序循环,结果也会以微秒级别的顺序完成。我打赌有更简洁的解决方案,但将async设置为false可以解决它。我知道人们不建议这样做,所以我怎么能确保我的行以正确的顺序存储和呈现?
我也想知道为什么当我将async设置为false时,我的showLoader()和removeLoader()函数没有运行?
$('#move-rows-btn').on('click', function(e) {
e.preventDefault();
$(document).showLoader();
$(this).closest('.project').find('.sub-table tbody tr').each(function() {
var row = $(this);
var id = row.data('id');
var response;
$.ajax({ type: "GET",
url: "?ajax=move_row&id="+id,
async: false
}).done(function(response) {
if( response != 0 )
{
row.detach().appendTo('#main-table tbody').attr('id', 'rowid-'+response);
}
});
});
$(document).removeLoader();
});