【问题标题】:how to get file listing using jquery ajax如何使用 jquery ajax 获取文件列表
【发布时间】:2013-12-26 11:47:02
【问题描述】:

我想获取文件列表(来自名为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();

【问题讨论】:

    标签: php jquery ajax


    【解决方案1】:

    试试这个

    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);
                   }
              });
    }
    

    【讨论】:

      【解决方案2】:

      scandir 是不好的做法 :(

      使用更快的解决方案:https://stackoverflow.com/a/30949072/257319

      【讨论】:

        猜你喜欢
        • 2017-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-16
        • 2012-06-13
        • 2016-11-04
        • 2014-10-07
        相关资源
        最近更新 更多