I have two functions that take arguments and are async:
updateCartNote(cartNote);
And
updateCartAttributes(attributeToUpdate);
Both of these use AJAX to update a shopping cart, the issue is, is that I have to run them synchronously. I've tried multiple ways with when
and then
and using callbacks, and nothing seems to work. My latest attempt is with the following:
function keepCartNoteAndDate(cartNote, deliveryDate){
console.log("keepCartNoteAndDate");
$.ajax({
url: '/cart/update.js',
data: 'note=' + cartNote,
type: "POST",
dataType: "js",
complete: function() {
updateCartAttributes({delivery_date: deliveryDate});
},
});
}
I extracted the AJAX function for updating CartNote
and then just put the updateCartAttributes
in the complete
section. But no luck.
Where did I go astray?