微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想获取文件列表(来自名为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可以单独运行,即正确列出文件.
但是我怎样才能将内部列表放入T div中?
我可以包含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();

解决方法:

尝试这个

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脚本

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐