由网友(抹不去记忆的念、)分享简介:我想获得的文件列表(从文件夹名为上传。get_files.php < PHP$ DIR ='上传/';$ A = SCANDIR($目录);$ B =计数($ A);为($ X = 2; $ X< $ B:$ X ++){回声< DIV CLASS ='filePass'>中;回声$...![jQuery Ajax](/d/file/2023/09-16/a2928d708f3827fd2b71ef47c1584f37.png)
我想获得的文件列表(从文件夹名为上传
。
get_files.php
< PHP
$ DIR ='上传/';
$ A = SCANDIR($目录);
$ B =计数($ A);
为($ X = 2; $ X< $ B:$ X ++)
{
回声< DIV CLASS ='filePass'>中;
回声$ A [$ X]
回声< / DIV>中;
}
?>
get_files.php
作品以及独自一人,也就是说,它正确地列出文件。
但我怎么能进去 insideT
DIV?名单
我可以包括 GET-files.php
,但我需要的,因为以后重新使用该功能来做到这一点使用jQuery的阿贾克斯。
函数get_files(){
$阿贾克斯({
网址:get_files.php,
输入:'得到'
});
$('#insideT)HTML(//这里我想要得到的文件清单)。
}
get_files();
解决方案
试试这个
get_files.php
< PHP
$ DIR ='上传/';
$ A = SCANDIR($目录);
$ B =计数($ A);
$水库='';
为($ X = 2; $ X< $ B:$ X ++)
{
$水库=< DIV CLASS ='filePass'>中。
。$水库= $ A [$ X]
$水库=< / DIV>中。
}
回声$水库;
?>
![jQuery Ajax](/d/file/2023/09-16/a2928d708f3827fd2b71ef47c1584f37.png)
阿贾克斯脚本
函数get_files(){
$阿贾克斯({
键入:GET,
网址:get_files.php
缓存:假的,
成功:函数(结果){
$(#insideT)HTML(结果)。
}
});
}
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();
解决方案
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);
}
});
}
相关推荐
最新文章