title: jQuery - How to call a callback with getjson
body: <p>I have the following callback:</p>
  
  <pre><code>var getData = function (callback) {
  
      var id = $("#Id").val();
  
      if (id.length === 0)
         return; 
  
     $.getJSON('api/data' + '?id=' + id)
      .done(function (data) {
          callback(data);
      }).fail(function (jqXHR, textStatus, err) {
          return;
      });
  
  }
  </code></pre>
  
  <p>I'm trying to call it as follows:</p>
  
  <pre><code>var id = 123;
  getData(function () {
       //TO DO: check if id exist in data
       console.log(data);
  });
  </code></pre>
  
  <p>But I get <code>reference error: data is not defined</code>. How do I get the data returned by the ajax request. I'm not too familiar with callbacks so bear with me as I'm still trying to get to grips with them.</p>