如何获取文件使用jQuery AJAX上市 [英] how to get file listing using jquery ajax
本文介绍了如何获取文件使用jQuery AJAX上市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得的文件列表(从文件夹名为上传
。
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>中。
}
回声$水库;
?>
阿贾克斯脚本
函数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);
}
});
}
这篇关于如何获取文件使用jQuery AJAX上市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文