title: jquery Cannot read property 'done' of undefined - avoid this
body: <p>I have a function which returns results (or not). The problem is when it does not return any value I get in the console the message </p>
  
  <blockquote>
    <p>cannot read property 'done' of undefined</p>
  </blockquote>
  
  <p>Which is true and I do understand the problem. Also, this error doesn't make my code stop working, but I would like to know if there's any chance of avoiding this?</p>
  
  <p>The function in ajax is:</p>
  
  <pre><code>function getDelivery(){
      var items = new Array();
  
      $("#tab-delivery tr").each(function(){
          items.push({"id" : $(this).find('.form-control').attr('id'), "id_option" : $(this).find('.form-control').val()});
      });
  
      if(items.length &gt; 0){
          return $.ajax({
              url: 'response.php?type=getDelivery',
              type: 'POST',
              data: {content: items}
          });
      }
  }
  </code></pre>
  
  <p>And to call it I use:</p>
  
  <pre><code>getDelivery().done(function(data){ // the problem is here
      if(data == false){
          return;
      }
  });
  </code></pre>
  
  <p>So, is there any way of avoid the error? I have tried without success the following:</p>
  
  <pre><code>if(items.length &gt; 0){
      return $.ajax({
          url: 'response.php?type=getDelivery',
          type: 'POST',
          data: {content: items}
      });
  }else{
      return false;
  }
  </code></pre>
  
  <p>And I get the error: </p>
  
  <blockquote>
    <p>Uncaught TypeError: undefined is not a function</p>
  </blockquote>