Saturday, December 15, 2018

Progressive call an API sequentially with an ordering defined by the items in an array with jQuery.

var addAddresses = function (addresses) {
   if (addresses.length == 0) {
      alert("All done!");
      return false;
   }
   var address = addresses.shift();
   $.ajax({
      type: "POST",
      url: "/AddressValidation",
      data: address,
      success: function(response) {
         $("#AddressValidationFormWrapper").append(response);
         AddAddresses(addresses);
      },
      error: function () {
         alert("Yikes!");
         AddAddresses(addresses);
      }
   });
};

No comments:

Post a Comment