0

I'm using the jQuery steps plugin and have this code below. I want the step to change only if the r variable is true. I did it like this and it is not working for me.

onStepChanging: function(event, currentIndex, newIndex) {
  var stepnum = parseInt(currentIndex) + 1;

  function getCartProducts(stepnum, callback) {
    return $.ajax({
      url: path + "/ajax.php?pg=checksurveyrequiredresponses",
      data: $("#sendresponses").serialize(),
      type: 'POST',
      dataType: 'json'
    });
  }

  var theruturn;

  getCartProducts(stepnum).done(function(r) {
    if (r) {
      theruturn = true;
    } else {
      theruturn = false;
    }
  }).fail(function(x) {
    console.log(x);
  });

  return theruturn;
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 1
    Can you fix the indentation of your code? Also, it starts with a... label? Or is this a piece that is inside some object structure? Can you complete the outside object? – trincot Jan 22 '22 at 19:59
  • You can't return anything from the `onStepChanging` function as it's an anonymous function. Even if you could, `thereturn` will be undefined as you set it in an async callback. – Rory McCrossan Jan 22 '22 at 20:04

0 Answers0