title: How to break out of PHP script during Ajax call and fire jQuery error handler with error?
body: <p>I want to be able to break out of my PHP script that is called with jQuery Ajax. How can I return an error back to jQuery to display to the user?</p>
  
  <p>PHP: </p>
  
  <pre><code>if($gift_card != null)
  {
  echo "not null";            
  }
  else 
  {
  echo "null";    
  exit();         
  }
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>error: function(jqXHR, textStatus, errorThrown) {
                          status.html("There was an error processing the request. " + errorThrown);  
                          setTimeout(function() {                                
                              status.fadeOut(); 
                          }, 4000);                            
                      },
                      success: function( data ) {
                          if (console &amp;&amp; console.log){
                              console.log( 'Sample of data:', data);
                          }                            
                          status.html('Email Sent Successfully.');   
                          setTimeout(function() {
                              status.fadeOut(); 
                          }, 4000); 
  </code></pre>
  
  <p>If I echo null and exit, it is still coming back as success. Do I just have to check the data in success and see what is returned and then go from there?</p>