title: Grabbing json object data
body: <p>I'm trying to create an AJAX form that shows an error or success message when the field is filled in correctly. This is my code:</p>
  
  <pre><code>$('#name').keyup(function() {
      var name = $('#name').val();
      $.post('core/name_processing.php', { name: name }, function(data) {
          if (data.name === 'nodata') {
              $('#name_check').html('&amp;nbsp;');
              $('.input_feedback').fadeOut('fast');
              $('.input_success').fadeOut('fast');
          } else if (data.name === 'success') {
              $('#name_check').html(data.name);
              $('.input_feedback').fadeOut('fast');
              $('.input_success').fadeIn('fast');
          } else {
              $('#name_check').html(data.name);
              $('.input_feedback').fadeIn('fast');
          }
      });
  });
  </code></pre>
  
  <p><em>'#name'</em> is the input field.</p>
  
  <p>Here's the PHP:</p>
  
  <pre><code>&lt;?php
  
  $result = array();
  
  if (isSet($_POST['name'])) {
      if (empty($_POST['name'])) {
          $result['name'] = 'nodata';
      } else {
          $name = $_POST['name'];
          if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
              $result['name'] = "Only letters and white space allowed"; 
          } else if (strlen($name) &gt; 10) {
              $result['name'] = 'success';
          } else {
              $result['name'] = strlen($name).' characters';
          }
      }
  }
  
  echo json_encode($result);
  
  ?&gt;
  </code></pre>
  
  <p>The code worked just fine when I didn't use an array, but since I want to add more input fields I will need to return the data in an array. The problem seems to be that <em>data.name</em> is not a valid value, it does not grab the data as it should. How can I fix this?</p>
  
  <p><em>data</em> returns <code>{"name":"... characters"}</code>, <code>{"name":"nodata"}</code> and <code>{"name":"success"}</code> which seems to be correct.</p>