I need to paste some data in the DOM when a recursive ajax function ends its recursion.
The problem I have is that "$.when().done()" will trigger in the first step of rescursion but I need that it triggers on the last step of recursion, when recursion ends.
I really have no idea how to achive it, any help will be kindly apreciated!
function recursiveFunction(data) {
// do something with data
// and remove elements processed from data
var param = {
"data" : data
};
return $.ajax({
data: param,
url: 'script.php',
type: 'post',
success: function(response) {
recursiveFunction(response);
},
});
}
$.when(recursiveFunction(data)).done(function(response){
paintData();
});