title: Passing JSON object from php to JS via Ajax
body: <p>I am trying to pass a JSON object from a php script to a Javascript file with Ajax. The code below worked for a simple string, but I am now trying to amend it to work with multiple strings contained within a JSON object. I have pasted extracts of each file below. What am I doing wrong?</p>
  
  <p>This is a extract from the html/javascript file which is creating the request...</p>
  
  <pre><code>  function retrieveAircraftInfo(str) {
  
      var xmlhttp;
      if (str.length==0) { 
       document.aircraftRegForm.aircraftManufacturer.value="";
       return;
       }
  
  
      if (window.XMLHttpRequest) {
       // code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp = new XMLHttpRequest();
       } else {
          // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
  
  
      xmlhttp.onreadystatechange = function() {
  
              if (xmlhttp.readyState==4) {
                  var aircraftDataJSON = xmlhttp.responseText.evalJSON();
                  document.aircraftRegForm.aircraftManufacturer.value = aircraftDataJSON.manufacuter;
                  document.aircraftRegForm.aircraftType.value = aircraftDataJSON.type;
                  document.aircraftRegForm.aircraftPopularName.value = aircraftDataJSON.popularName;
                  document.aircraftRegForm.aircraftGenericName.value = aircraftDataJSON.genericName;
             }
       }
      xmlhttp.open("GET","scraper.php?q="+str,true);
      xmlhttp.send();
      }
  </code></pre>
  
  <p>This is an extract from the php file which is doing the database search:</p>
  
  <pre><code>$aircraftDataArray = array("manufacturer" =&gt; $extractedManufacturer,
      "type" =&gt; $extractedType,
      "popularName" =&gt; $extractedPopularName,
      "genericName" =&gt; $extractedGenericName);
  
  echo json_encode($aircraftDataArray);
  </code></pre>