0

My foo() function returns a 1 value if a person has logged on the selected machine. It returns 0 if the machine is available. I need to use this variable (log) in a button click event. However I simply can't figure out how to write a callback in this scenario.

function foo(callback) {
  $.ajax({
    type: 'GET',
    url: '/api/machine/',
    dataType: "JSON",
    data: "data",
    success: function(data) {
      callback(data)

      $.each(data, function(i, data) {
        if (data.machinename == $("#DropDownList2").val()) {
          var log = data.selected;
          alert('Machine status is: ' + log);
        };
      });
    }
  });
}

foo(function(data) {
  alert('Data2 is: ' + data);
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

0 Answers0