I am pretty sure I am creating a race but I do not know how to go about fixing it… any ideas?
cheers,
[code=php]
$(‘.add-items’).live(‘click’, function(evt) {
if (evt.button != 0) return; // ignore right-click
evt.preventDefault();
var items = $(this).attr(‘href’).substr(1).split(‘,’);
// now items is [‘G400180’, ‘G400181’]
// Disable the link to prevent repeated orders
$(this).attr(‘disabled’,’disabled’);
// Execute the orders using ajax
var remaining_requests_cnt = items.length;
for (var i = 0; i < items.length; i++) {
$.ajax({
url: ‘/cgi/cart.cgi?’+items[i],
success: function() {
if (–remaining_requests_cnt == 0) {
top.location.href=”http://www.feelgoodlightups.com/cgi/cart.cgi?viewcart”;
}
},
error: function() {
alert(‘Error occurred. Check the content of your cart.’);
location.reload();
},
})
}
});