title: I can not get the array json response
body: <p>I am trying to send with PHP and jQuery an array response, but it is not working my PHP code is:</p>
  
  <pre><code>public function get(Request $request)
  {
      $pre_images = Pre_Image::all();
  
      foreach ($pre_images as $pre_image) {
          $data[] = array("file" =&gt; $pre_image-&gt;image);
      }
  
      echo json_encode($data);
  }
  </code></pre>
  
  <p>It creates the array and I encode it to be sent. Then my jQuery is:</p>
  
  <pre><code>$( 'body' ).on( "click", '#add_value', function() {
      $.ajax({
          type: 'POST',
          url: '/pre_image/get',
          success:function(files)
          {
              var len = files.length;
  
              var values = '';
  
              for(var i=0; i&lt;len; i++){
                  values = values + '&lt;div class="col-md-3"&gt;'+ files[i].file +'&lt;div class="col-md-3"&gt;';
              }
  
              $(".values").append('&lt;div class="row" style="padding-left:20px; padding-right:20px;"&gt;&lt;div class="col-md-3"&gt;&lt;div class="form-group"&gt;&lt;br&gt;&lt;label class="control-label mb-10"&gt;Nombre de las Opciones (Ejem: Rojo, Azul.)&lt;/label&gt;&lt;input type="text" class="form-control" name="value_name"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-3"&gt;&lt;div class="form-group"&gt;&lt;br&gt;&lt;label class="control-label mb-10"&gt;Opciones (Ejem: 38, 39, 40.)&lt;/label&gt;&lt;input type="text" class="form-control" name="value_name"&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-6"&gt;&lt;div class="form-group"&gt;&lt;br&gt;&lt;label class="control-label mb-10"&gt;Imagenes &lt;/label&gt;'+values+'&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;');
          }
      });
  
      return false;
  });
  </code></pre>
  
  <p>I get the response in the success but the first problem that I get it's when I use files.length; it counts 37 and it should count 1 because in this moment the database just has one record, but it is count the leght of the word I mean 272621621287272.jpg  it is count how length is the word.</p>
  
  <p>The second problem that I get it's that I use to read the array, and it returns me undefined. How is it possible if it has a record stored in the array which it comes from PHP response. </p>
  
  <p>I hope you can help me Thanks.jquery</p>