我想获取文件列表(来自名为 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
单独工作效果很好,即它正确列出了文件。
但是如何获取 insideT
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);
}
});
}
关于php - 如何使用 jquery ajax 获取文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20784301/