0

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?

ToddT
  • 3,084
  • 4
  • 39
  • 83
  • this looks fine, what kind of error are you getting? – ztadic91 Nov 29 '17 at 22:25
  • `I have to run them synchronously` <= no you don't or you are using the wrong terminology. What are you trying to accomplish? One run function only after the other has completed? Something else? What is "not working" (paraphrasing "nothing seems to work") – Igor Nov 29 '17 at 22:28

0 Answers0