how do start a function like redirecting to a new page when .each is done looping my elements?
this is my current code:
$('#tabCurrentFriends > .dragFriend').each(function(){
var friendId = $(this).data('rowid');
$.ajax({
type: "POST", url: "../../page/newtab.php", data: "action=new&tabname=" + tabname + "&bid=" + brugerid + "&fid=" + friendid,
complete: function(data){
}
});
});
You can use
$.when()/$.then()to redirect your users after all the AJAX requests are done:Edit – to use
whenwith an array,applymust be used:jQuery AJAX requests create deffered objects that resolve when their complete function fires. This code stores those deffered objects in an array and when they all resolved the function within
.then()is run.Docs:
$.when(): http://api.jquery.com/jquery.when$.then(): http://api.jquery.com/deferred.then/