title: JSON response from PHP script being enclosed in <head></head><body> ... <body>
body: <p>I am trying to debug a simple PHP/JSON/jQuery problem.</p>
  
  <p>The following PHP script:</p>
  
  <pre><code>header('Content-type: text/javascript');
  echo json_encode(array('type'=&gt;'error','message'=&gt;'arg')); 
  </code></pre>
  
  <p>is being consumed by jQuery but when the line:</p>
  
  <pre><code>var results = jQuery.parseJSON(responseText);
  </code></pre>
  
  <p>is executed, the jQuery JSON parser gives the following:</p>
  
  <pre><code>uncaught exception: Invalid JSON: &lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;pre&gt;{"type":"error","message":"oops!"}&lt;/pre&gt;&lt;/body&gt;
  </code></pre>
  
  <p>Obviously the head/body/pre are not supposed to be returned.</p>
  
  <p>I cannot see any hidden characters nor anything out of order in my PHP code..</p>
  
  <p>Any ideas?</p>