javascript - jQuery each(), process one by one after inner ajax comepletes -
javascript - jQuery each(), process one by one after inner ajax comepletes -
i have code
$("[input]").each(function(){ var info = $(this).val(); $.post('someurl.php',{data:data},function(result){ alert(result); }); });
now, when open network tab, post ajax requests seems started simultaneously, want accomplish 1 one. means when 1 ajax request completes, want each() wait loop again.
how can accomplish this?
it because of asynchronous nature of ajax, seek like
process($("[input]")); function process($inputs) { if (!$inputs.length) { return; } var $input = $inputs.eq(0); var info = $input.val(); $.post('someurl.php', { data: info }, function (result) { console.log(result); }).always(function () { process($inputs.slice(1)) }); }
demo: fiddle
javascript jquery ajax
Comments
Post a Comment