lilmer Posted October 8, 2013 Share Posted October 8, 2013 Is there any solution on how to process the next loop after the success request on the first ajax request on the first call? E.g. $('.email').each(function(){ $.ajax({ Processs!!! }); }); or make a wait for the next loop after an ajax call? is this possible? I don't want to use async:false because it makes chrome browser to freeze. Any advice? Quote Link to comment https://forums.phpfreaks.com/topic/282796-perform-next-loop-after-the-finish-of-ajax-request/ Share on other sites More sharing options...
codefossa Posted October 8, 2013 Share Posted October 8, 2013 (edited) $.ajax({ // Some stuff .. }).done(function() { // Call Next }); You can use .done() for successful, .fail() for unsuccessful, or .always() to always trigger after it runs. You could use .done() and .fail() together I believe to do something depending on which occurs. Edited October 8, 2013 by Xaotique Quote Link to comment https://forums.phpfreaks.com/topic/282796-perform-next-loop-after-the-finish-of-ajax-request/#findComment-1453052 Share on other sites More sharing options...
Solution lilmer Posted October 9, 2013 Author Solution Share Posted October 9, 2013 What I mean is it will perform the next loop after an ajax process succeeded. . but I got it already. $('#test').click(function(){ var newArray =new Array('sample','code','for','testing'); var all = newArray.length; var i = 0; ajaxProcess(i); function ajaxProcess(i){ if(i < all){ $.ajax({ type: "POST", url: 'ajax.php', data: {'test': newArray[i]['cars']}, dataType: 'html', success:function(data){ i++ alert(data); $('div#output').html(data); ajaxProcess(i); } }); } } }); Quote Link to comment https://forums.phpfreaks.com/topic/282796-perform-next-loop-after-the-finish-of-ajax-request/#findComment-1453186 Share on other sites More sharing options...
codefossa Posted October 9, 2013 Share Posted October 9, 2013 Yes, you would use them basically the same way. function myFunc(i) { $.ajax( { // Something .. }).done(function() { // Success - Call Next myFunc(i + 1); }).fail(function() { // Failed - Retry? myFunc(i); }); } Quote Link to comment https://forums.phpfreaks.com/topic/282796-perform-next-loop-after-the-finish-of-ajax-request/#findComment-1453261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.