Skip to content

Instantly share code, notes, and snippets.

@dan-gamble
Created July 2, 2018 09:24
Show Gist options
  • Save dan-gamble/5fdf97fac8193126a5c3279752309efc to your computer and use it in GitHub Desktop.
Save dan-gamble/5fdf97fac8193126a5c3279752309efc to your computer and use it in GitHub Desktop.

Before

function calculateItems (value, index) {
  $.ajax({
    type: "POST",
    url: "https://www.hyperioncomposites.com/calculators/decking-calc-v3.php",
    data: value,
    async: false,
    success: function (data) {
      calcResults[index] = JSON.parse(data);
      calcResults[index].active = 1;
    },
  });
}

After

function calculateItems (value, index, callback) {
  $.ajax({
    type: "POST",
    url: "https://www.hyperioncomposites.com/calculators/decking-calc-v3.php",
    data: value,
    async: true,
    success: function (data) {
      calcResults[index] = JSON.parse(data);
      calcResults[index].active = 1;

      callback()
    },
  });
}

Before

calculateItems(calcInput);
isActive = true;

if (isActive) {
  organiseItems();
}

After

calculateItems(calcInput, undefined, function () {
  isActive = true;

  if (isActive) {
    organiseItems();
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment