So a XHR is run inside a loop and I would like to execute a function after all the XHR complete, I tried this with promises as follows.
var promises = [];
for(var i=0;i<5;i++){
promise = $.ajax({
type: "POST",
url : data_url,
data:pdata
});
promises.push(promise);
}
$.when(promises).then(function(){
window.location.href = '/cart?edit_order=true'
})
The problem is the redirect happens before the AJAX is completed, what am I missing?