title: PHP returning JSON to JQUERY AJAX CALL
body: <p>I am still struggling to get my head around the ins and out of JQUERY, AJAX and PHP.</p>
  
  <p>I can now call the PHP OK, process the form elements and send an email, but I am not handling the return to the AJAX.  I am always getting the <code>error:</code> selector activated and when I try to list the supposed JSON returned, I get info, that is obviously wrong.</p>
  
  <p>PHP with supposed JSON return</p>
  
  <pre><code>&lt;?php
  
  touch('phpTouch.txt');
  // process email
  $email=1;
  if ($email) {
      $value = array('return' =&gt; 1, 'msg1' =&gt; 'Message sent OK, we will be in touch ASAP');
  } else {
      $value = array('return' =&gt; 0, 'msg1' =&gt; 'Message Failed, please try later');
  }
  $output = $json-&gt;encode($value);
  echo $output;
  
  ?&gt;
  </code></pre>
  
  <p>Javascript  and AJAX</p>
  
  <pre><code>function submitForm(evt) {
      $('#msgid').html('&lt;h1&gt;Submitting Form (External Routine)&lt;/h1&gt;');
      if ($('#formEnquiry').valid() ) {
          $("#msgid").append("&lt;h1&gt;(Outside Ready) VALIDATED send to PHP&lt;/h1&gt;");
              $.ajax({
              url: "ContactFormProcess3.php",
              type: "POST",
              data: $('#formEnquiry').serialize(),
              dataType: "json",
              success: function (data) {
                  alert("SUCCESS:");
                  for(var key in data) {
                      $('#msgid').append(key);
                      $('#msgid').append('=' + data[key] + '&lt;br /&gt;');
                  }
              },
              error: function (data) {
                  alert("ERROR: ");
                  for(var key in data) {
                      $('#msgid').append(key);
                      $('#msgid').append('=' + data[key] + '&lt;br /&gt;');
                  }
              }
          });
      } else {
          $('#msgid').append('&lt;h1&gt;(Outside Ready) NOT VALIDATED&lt;/h1&gt;');
      }
      evt.preventDefault();
  };
  </code></pre>
  
  <p>Listing of supposed JSON data</p>
  
  <pre><code>readyState=4
  setRequestHeader=function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this}
  getAllResponseHeaders=function (){return s===2?n:null}
  getResponseHeader=function (a){var c;if(s===2){if(!o){o={};while(c=bF.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c}
  overrideMimeType=function (a){s||(d.mimeType=a);return this}
  etc etc 
  </code></pre>
  
  <p>If anyone can advise as to what stupid mistake I have made, then I would be most grateful.</p>