title: Parsing PHP response: Uncaught SyntaxError: Unexpected token <
body: <p>I'm using AJAX to make a call to a PHP script. The only thing I need to parse from the response is a random ID generated by the script. The problem is that the PHP script throws a number of errors. The errors are actually fine and don't get in the way of the program functionality. The only issue is that when I run </p>
  
  <pre><code>$.parseJSON(response)
  </code></pre>
  
  <p>I get: </p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token &lt; 
  </code></pre>
  
  <p>Since the PHP response starts with an error:</p>
  
  <pre><code>&lt;br /&gt; 
  &lt;b&gt;Warning&lt;/b&gt;:
  </code></pre>
  
  <p>I'm wondering how to change the PHP or JS such that it can parse out the ID despite the errors. </p>
  
  <p>PHP:</p>
  
  <pre><code>  $returnData = array();
    $returnData['id'] = $pdfID;
    echo json_encode($returnData); 
    ...
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code> function returnReport(response) {
      var parsedResponse = $.parseJSON(response);
      console.log(parsedResponse);
      pdfID = parsedResponse['id']; 
  </code></pre>
  
  <p>I know that the warnings should be resolved, but the warnings are not functionality critical for now and more importantly</p>
  
  <p>1) Even if these warnings are resolved new ones may come up down the line and the JSON should still be properly parsed and </p>
  
  <p>2) In addition to the warnings there are 'notices' that cause the same issue.</p>