title: How to access array elements in ajax response received from PHP?
body: <p>jQuery code of ajax function is as follows:</p>
  
  <pre><code>$(document).ready(function() {
  $("#zip_code").keyup(function() {
      var el = $(this);
      var module_url = $('#module_url').val();
  
      if (el.val().length === 5) {
        $.ajax({
          url : module_url,
          cache: false,
          dataType: "json",
          type: "GET",
          data: {
              'request_type':'ajax', 
              'op':'get_city_state',
              'zip_code' : el.val()
          },
          success: function(result, success) { alert(result.join('\n'));
            $("#city").val(result.place_name);
            $("#state_code").val(result.state_code);
          }
        }); 
      }
    });
  });
  </code></pre>
  
  <p>PHP code snippet is as follows :</p>
  
  <pre><code>case "get_city_state":
  
        // to get the city and state on zip code.
        $ret = $objUserLogin-&gt;GetCityState($request); 
  
        if(!$ret) { 
          $error_msg = $objUserLogin-&gt;GetAllErrors();
          list($data) = prepare_response($request);
          $smarty-&gt;assign('data', $data);    
        } else {
          $data = $objUserLogin-&gt;GetResponse();
  
          echo $data;
        }     
  
        die;
        break;
  </code></pre>
  
  <p>In PHP code the $data contains data in following manner :</p>
  
  <pre><code>&lt;pre&gt;Array
  (
      [id] =&gt; 23212
      [zip_code] =&gt; 28445
      [place_name] =&gt; Holly Ridge
      [state_code] =&gt; NC
      [created_at] =&gt; 1410875971
      [updated_at] =&gt; 1410875971
  )
  &lt;/pre&gt;
  </code></pre>
  
  <p>From the above data(i.e. response which will be available in variable result in ajax response) I want to access only two fields place_name and state_code.</p>
  
  <p>I tried printing the content of result variable using <code>alert(result)</code> in console but I get the word <code>Array</code> </p>
  
  <p>How to achieve this is my doubt?</p>
  
  <p>Thanks in advance. </p>