title: Error sending form by Ajax and PHP
body: <p>Ok so i got a form that i want to sent with information inputted by the user...
  I wonna do this with Ajax and php but i have a problem with the syntax i guess i'll post my javascript code and php code below and hopefulle someone can help me out</p>
  
  <p>this is the code i use to send the data from the form:</p>
  
  <pre><code>$('#register').submit(function(e) {
                e.preventDefault(); 
              // make the $.post call synchronous  !!important
              $.ajaxSetup({async: false});
              $.ajaxSetup({
                  beforeSend: function(xhr, status) {
                      // TODO: show spinner
                       $(".loading").show();
                  },
                  complete: function() {
                      // TODO: hide spinner
                       $(".loading").hide();
                  }
              });
              //use ajax to run the check  
              $.ajax({ 
                  url: "phpAction/register-action.php",
                  type: 'POST',
                  data: $(this).serialize(),
                  dataType: 'json',
                  success: function(data) {   
                      if (data)
                      {
                      window.scrollTo(0,100);
  
                      $('#melding').fadeIn(2000);
                      $('#melding').delay(10000).fadeOut(2000);
                      alert(data);
                      } 
                      else
                      {
                      // error
                      $('#melding').addClass("false");
                      window.scrollTo(0,100); 
                      $('#melding').fadeIn(2000);
                      $('#melding').delay(10000).fadeOut(2000);
                      alert(data);
                      }
  
                  },
                  error: function(xhr, textStatus, errorThrown){
                  alert(xhr + textStatus + errorThrown);
                  alert(textStatus);
                  alert(errorThrown);
              }
  
              });
              });
  </code></pre>
  
  <p>And at a certain when something goes wrong in the php file i do this to return the data to the ajax call:</p>
  
  <pre><code>//Registreren mislukt
              $errors = '';
              foreach($aErrors_Leeg as $Error)
              {
                  $errors .= $Error.'&lt;br&gt;';
              }
              foreach($aErrors_Andere as $Error)
              {
                  $errors .= $Error.'&lt;br&gt;';
              }
  
  
              $result = array(
                  'status' =&gt; 'error',
                  'titel' =&gt; 'Registreren Mislukt :(', // whatever you want
                  'message' =&gt; 'Test'//$errors
              );
              echo json_encode($result);
  </code></pre>
  
  <p>Or return this if there are no errors on the inputted fields:</p>
  
  <pre><code>//Registreren gelukt
                   $result = array(
                  'status' =&gt; 'success',
                  'titel' =&gt; 'Registreren Gelukt !', // whatever you want
                  'message' =&gt; ''
  
                  );
                  echo json_encode($result);
  </code></pre>
  
  <p>What is similear with the above...</p>
  
  <p>The Error function gets trigerred when I send a empty form and tells: parseErrorSyntaxError : Unexpected token &lt;</p>