Question: I want to get files list (from a folder named `uploads`. 

get\_files.php

```
<?php
$dir = 'uploads/';
$a = scandir($dir);
$b=count($a);

for($x=2;$x<$b;$x++)
   {
   echo"<div class='filePass'>";
     echo $a[$x];
     echo "</div>";
   }
?>

```

`get_files.php` works well as alone, i.e. it properly lists the files.  

But how can I get the list inside `insideT` div ?  

I can include `get-files.php` but I need to do this using jquery ajax, because of reusing the function later.

```
function get_files(){
   $.ajax({
    url : 'get_files.php',
    type : 'get'
    });
    $('#insideT').html(//here I want to get the file listing);
    }
get_files();

```

Answer: 
Try this

get\_files.php

```
<?php
$dir = 'uploads/';
$a = scandir($dir);
$b=count($a);
$res = '';
for($x=2;$x<$b;$x++)
   {
     $res.= "<div class='filePass'>";
     $res.= $a[$x];
     $res.= "</div>";
   }
echo $res;
?>

```

Ajax script

```
function get_files(){
    $.ajax({
               type: "GET",
               url: "get_files.php",
               cache: false,
               success: function(result){
                     $("#insideT").html(result);
               }
          });
}

```
*`scandir` is bad-practice :(*

Use faster solution: <https://stackoverflow.com/a/30949072/257319>