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

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -