如何使用jquery ajax获取文件列表

qad*_*nza 2 php ajax jquery

我想获取文件列表(来自名为的文件夹)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>";
   }
?>
Run Code Online (Sandbox Code Playgroud)

get_files.php单独工作,即它正确列出文件.
但是如何才能获得insideTdiv中的列表?
我可以包括,get-files.php但我需要使用jquery ajax,因为稍后重用该函数.

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

use*_*773 6

试试这个

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;
?>
Run Code Online (Sandbox Code Playgroud)

Ajax脚本

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