title: Laravel AJAX can't get response
body: <p>I'm working with the Laravel framework and I'm making an AJAX request to send an email. The request works fine and the mail is sent, the problem is I can't get the server response if the mail has been sent successfully or not. </p>
  
  <p>Here's the code (short version) wich is located under views/contact/mail.blade.php :</p>
  
  <pre><code>if( mail($to, $subject, $body,$headers) )  {
      $data = array( 'text' =&gt; Lang::line('contact.mail-success')-&gt;get() );
      return Response::json($data);
  } else {
      $data = array( 'text' =&gt; Lang::line('contact.mail-error')-&gt;get() );
      return Response::json($data);
  }
  </code></pre>
  
  <p>and here's the jquery :</p>
  
  <pre><code>$('#contact-form').submit(function() {
          var request = $.ajax({
              url: BASE+'/contact',
              type: 'post',
              data: { name: $('#name').val(), mail: $('#email').val(), message: $('#msg').val() },
              dataType:"json",
              success: function(data){
                 var message = $.parseJSON(data);
                 alert(message.text); // here I get the "cannot read property of null" in the console log
              }
          });
  
      return false;
  });
  </code></pre>
  
  <p>What am I doing wrong? Thanks for your help.</p>