title: How to use variable data after Ajax Call Success - Laravel
body: <p>I created a small file manager to manage my files. On the one hand, the folder structure is shown thanks to JsTree. On the right I would like that based on the click on the left folder I was shown the files contained in that folder.
  At the click an Ajax call is made which calls the selectFiles method to go through the routes. Now in the console i see the correct data, but i don't know how to use it into foreach in the blade.</p>
  
  <p><strong>AJAX:</strong></p>
  
  <pre><code>// chiamata Ajax per selezionare files in base all'id
  $('#treeview').on("select_node.jstree", function (e, data) {
      var id = data.node.id;
      $.ajax({
          type: 'POST',
          url: 'archivio_documenti/+id+/selectFiles',
          data: {id:id},
          success: function(data) {
              console.log('Succes!',data);
          },
          error : function(err) {
              console.log('Error!', err);
          },
      });
  });
  </code></pre>
  
  <p><strong>DocumentiController.php:</strong></p>
  
  <pre><code>/**
   * Selzionare files in base all'id della cartella
   */
  public function selectFiles(Request $request){
      try{
          $id = $request-&gt;id;
          $files = \App\Documento::where('cartella_id',$id)-&gt;get();
  
          return response()-&gt;json(compact('files'));
  
      }
      catch(\Exception $e){
          echo json_encode($e-&gt;getMessage());
      }
  }
  </code></pre>
  
  <p><strong>Route:</strong></p>
  
  <pre><code>Route::post('archivio_documenti/{id}/selectFiles', 'DocumentiController@selectFiles');
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>                    @foreach($files as $key =&gt; $file)
                          &lt;div id="myDIV" class="file-box"&gt;
                              &lt;div class="file"&gt;
  
                                  {!! Form::open(['method' =&gt; 'DELETE','route' =&gt; ['documento.destroy', $file-&gt;id]]) !!}
                                  &lt;button type="submit" class="#" style="background: none; border: none; color: red;"&gt;
                                      &lt;i class='fa fa-trash' aria-hidden='true'&gt;&lt;/i&gt;
                                  &lt;/button&gt;
                                  {!! Form::close() !!}
  
                                  &lt;a href="/documento/{{ $file-&gt;id }}/edit" class="#" role="button" style="text-align: center;"&gt;&lt;i class='fa fa-edit' aria-hidden='true'&gt;&lt;/i&gt;&lt;/a&gt;
  
                                  &lt;input id="myInput_{{$key}}" type="text" value="{{'project.dev/'.$file-&gt;path.'/'.$file-&gt;file}}"&gt;
                                  &lt;a href="#"&gt;&lt;i class="btnFiles fa fa-files-o" aria-hidden="true" data-id="{{$key}}"&gt;&lt;/i&gt;&lt;/a&gt;
  
                                  &lt;a href="{{' http://project.dev/'.$file-&gt;path.'/'.$file-&gt;file}}"&gt;
                                      &lt;span class="corner"&gt;&lt;/span&gt;
  
                                      &lt;div class="icon"&gt;
                                          &lt;i class="img-responsive fa fa-{{$file-&gt;tipo_file}}" style="color:{{$file-&gt;color_file}}"&gt;&lt;/i&gt;
                                      &lt;/div&gt;
                                      &lt;div class="file-name"&gt;
                                          {{$file-&gt;file}}
                                          &lt;br&gt;
                                          &lt;small&gt;Update: {{$file-&gt;updated_at}}&lt;/small&gt;
                                      &lt;/div&gt;
                                  &lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      @endforeach
  </code></pre>