title: How to get JSON string into JavaScript from responsetext
body: <p>so I've tried this for the entire day but can't seem to solve it.. I have some AJAX getting a JSON string from a PHP script, and now I want to get it into JavaScript.</p>
  
  <p>What I've tried is this:</p>
  
  <pre><code>var xmlhttp;
  xmlhttp=new XMLHttpRequest();
  xmlhttp.onreadystatechange=function()
  {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      var obj = jQuery.parseJSON(xmlhttp.responseText);
  
      }
  }
  xmlhttp.open("GET","back.php?q="+query,true);
  xmlhttp.send();
  </code></pre>
  
  <p>But all I get is </p>
  
  <blockquote>
    <p>Uncaught SyntaxError: Unexpected token &lt; x.extend.parseJSON xmlhttp.onreadystatechange</p>
  </blockquote>
  
  <p>I've tried all type of code like </p>
  
  <pre><code>obj = JSON.parse(xmlhttp.responseText);
  alert(obj.length);
  </code></pre>
  
  <p>Whatever I do I basically get the error above.. don't know what to do.. I really wanna solve this with jQuery/JS..</p>
  
  <p>Thanks alot for any help!</p>