title: SyntaxError: Unexpected end of input at parse
body: <p>The following JS code snippet:</p>
  
  <pre><code>    var data_JSON = {
          input: 'test',
          message: 'Sending...'
      };
  
      $.ajax({
          url: 'main_php.php',
          type: 'POST',
          data: data_JSON,
          dataType : 'json',
          contentType: 'application/json',        
          success: alert(data),       
          error: function (request, status, error) {      
              alert(error);
          }
      }); 
  </code></pre>
  
  <p>And the following associated PHP code (main_php.php):</p>
  
  <pre><code>if ($_POST){    
      $vals = array(
          'input'     =&gt; $input,
          'message'   =&gt; $message
      );
      header('Content-Type: application/json');
      echo json_encode($vals);        
  }
  </code></pre>
  
  <p>Always result error (<code>error</code> runs in <code>$.ajax</code>), whatever I tried. In the browser's developer console, I could explore the complete length of the <strong>error message</strong>: </p>
  
  <blockquote>
    <p>SyntaxError: Unexpected end of input at parse (native) at ajaxConvert
    ([...]/jquery-3.0.0.js:8544:19) at done
    ([...]/jquery-3.0.0.js:9011:15) at XMLHttpRequest.
    ([...]/jquery-3.0.0.js:9303:9)</p>
  </blockquote>
  
  <p>Which is <em>exactly</em> the point where the JSON is failed to parse? What is the reason of this error and how can I solve it?</p>
  
  <p>Note: <code>JSON.stringify</code> did not work, if that helps anything.</p>