I call ajax in loop then use the result of those ajax calls, then make another call.As u can see below, in my case I solved it with setTimeout which is an ugly solution.
function get_something(some_arr) {
$.each(some_arr, function(i, obj) {
//call in loop
$.ajax({
url: "example.com",
complete: function(data) {
json = data
},
error: function(data) {
console(data);
},
});
});
setTimeout(function() {
$.ajax({
type: 'POST',
url: 'example.com/anothe_endpoint',
data: {
data: json
},
async: false,
success: function(data, status) {
}
});
}, 5000);
}
How do I execute my second ajax after the ajax in loops in done? I tried to add async to false but without timeout it still failed.