I need to access an API but I dont want to shoot with 100 requests at the same time so I want to make 1 request per second so I write:
$.each(added_collections, function(index, collection) {
$.each(collection, function(index1, page) {
$.each(page, function(index2, product) {
setTimeout(function() {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: '/get_data',
dataType: "json",
data: meta_data,
success: function(data) {
console.log(data);
},
error: function(data){
console.log(data);
}
});
}, 1000);
});
});
});
but this code do not make 1second between requests
How I can make 1 ajax call per second