I have this ajax function, that returns an array of prices:
function get_date_price(checkdate, type_r) {
return $.ajax({
type: "POST",
url: "hotels/get_check_date_price",
data: {id: $("#hotel_id").val(), checkdate1: checkdate, type_r1: type_r},
dataType: "JSON",
cache:false,
success:
function(data){
}
});
}
Then I want to call this function in a loop and calculate the total price, I use $.when
to wait for every ajax call to be completed, so that the returned price is correct (else it returns 0)
var total = 0;
for(var i = 0; i < $("#nights").val(); i++){
$.when(get_date_price("02/09/2016","Chambre Single")).then(function (v) {
total += parseFloat(v[1][0].price);
console.log(total);
});
}
When the loop contains, for example, 5 iterations, all works perfectly, when the number of iteration increases, some requests return 403! :
PS: I have remarqued that in a private navigation, the code is working without errors!