与jQuery同步运行2个异步函数

时间:2017-11-29 22:18:02

标签: jquery ajax asynchronous

我有两个带参数的函数,它们是异步的:

updateCartNote(cartNote);

updateCartAttributes(attributeToUpdate);

这两个都使用AJAX更新购物车,问题是,我必须同步运行它们。我已尝试使用whenthen以及使用回调的多种方式,似乎没有任何效果。我最近的尝试是:

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});
    },
  });
}

我提取了AJAX函数以更新CartNote,然后将updateCartAttributes放在complete部分。但没有运气。

我哪里误入歧途?

0 个答案:

没有答案
相关问题