title: jQuery Post retrieve PHP echo on Error
body: <p>I am trying to create a popup modal that will display text echoed from a php submission script. So far it works for a success and prints the echoed content but I also want to catch echoed messages when an exception occurs in the php script.</p>
  
  <p>popnotify is a seperate js function that takes text input and displays the modal with the text as a paragraph.</p>
  
  <p>createuser.php</p>
  
  <pre><code>try:
      ......
      echo 'Successfully created a new user';
  }
  catch (PDOException $ex){
      echo "Something went wrong when creating a new user";
      http_response_code(403);
      die();
  }
  </code></pre>
  
  <p>.js</p>
  
  <pre><code>jQuery("#load_form").on("click","#create_submit",function(event){
  event.preventDefault();
  var to_submit = $("#s_form").serialize();
  var formLink = $("#s_form").attr('action');
  jQuery('#load_form').find('input, select, button').prop('disabled', true);
  
  $.post(formLink,to_submit)
  .done(function(data){
      popnotify_success(data);
  })
  .fail(function(data){ 
      popnotify_fail(data);
  })
  .always(function(){
      jQuery('#load_form').find('input, select, button').prop('disabled', false);  
  });  });
  </code></pre>