title: Display json_encode array from ajax result
body: <p>I have this result</p>
  <p><code>{&quot;policy&quot;:[{&quot;id&quot;:&quot;1&quot;,&quot;policy_name&quot;:&quot;Policy 1&quot;,&quot;description&quot;:&quot;Testing&quot;,&quot;status&quot;:&quot;Active&quot;,&quot;valid_until&quot;:&quot;2022-05-18&quot;,&quot;tags&quot;:&quot;Test&quot;,&quot;active&quot;:&quot;0&quot;,&quot;date_added&quot;:&quot;2022-05-18 05:36:02&quot;}]}</code></p>
  <p>And I want to display the <code>policy_name</code> from the array and I've tried to alert it using this <code>alert(response['policy'].policy_name);</code> but I have an error.</p>
  <p><code>43:4801 Uncaught TypeError: Cannot read properties of undefined (reading 'policy_name')</code></p>
  <h2>Updated</h2>
  <p>This is my whole code:</p>
  <p><em><strong>AJAX</strong></em></p>
  <pre><code>$(&quot;*[id^='pol_action']&quot;).each(function() {
              $(this).change(function(){ 
                  var value = $(this).val();
                  var id = $('option:selected', this).attr('r-id');
                 
  
                  if($(this).val() == 'edit')
                  {
                      $.ajax({
                          url: &quot;&lt;?php echo base_url();?&gt;admin/leads/getPolData&quot;,
                          type: &quot;POST&quot;,
                          data: {id: id},
                          success: function(response){
                              
                          $('#update_policy_modal').modal('show');
                              alert(response['policy'].policy_name);
                              console.log(response);
                          },
                              error: function(data){
                                  console.log('error');
                              }
                      });
                  }
                  else if ($(this).val() == 'delete')
                  {
                      
                  }
              });
          }); 
  </code></pre>
  <p><em><strong>Controller</strong></em></p>
  <pre><code>public function getPolData()
      {
          $id = $this-&gt;input-&gt;post('id');
          
          $policy = $this-&gt;leads_model-&gt;getDataPol($id);
          $this-&gt;page_data['policy'] = $policy;
  
          echo json_encode($this-&gt;page_data);
      }
  </code></pre>
  <p><em><strong>Model</strong></em></p>
  <pre><code>public function getDataPol($id)
      {
          $where = array(
              'id'       =&gt; $id,
            );
  
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('tblpolicies');
          $this-&gt;db-&gt;where($where);
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result();
      }
  </code></pre>
  <p>What can I try to resolve this?</p>