html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf8"/>
 <title>jQuery async treeview</title>
 <link rel="stylesheet" href="../jquery.treeview.css" />
    <link rel="stylesheet" href="../red-treeview.css" />
 <link rel="stylesheet" href="screen.css" />
 <script src="../lib/jquery.js" type="text/javascript"></script>
 <script src="../lib/jquery.cookie.js" type="text/javascript"></script>
 <script src="../jquery.treeview.js" type="text/javascript"></script>
 <!-- 异步加载数据时用到的库 -->
 <script src="../jquery.treeview.async.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function(){
  $("#black").treeview({
   url: "source.php"
  })
 });
 </script>
 </head>
 <body>
 <h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-treeview/%22%3EjQuery Treeview Plugin</a> Demo</h1>
 <div id="main">
 <ul>
  <li><a href=".">Main Demo</a></li>
  <li><a href="source.phps">服务器端代码</a></li>
 </ul>
 <h4>Lazy-loading tree</h4>
 <ul id="black">
 </ul>
</div>
</body></html>
php文件:
<?php
if ($_REQUEST['root'] == "source"){
$province=array();
$dir="C:/QQDownload";
$handle=opendir($dir."."); 
while (false !== ($file = readdir($handle)))
{
   if ($file != "." && $file != "..") {
    $arr=array();
    $arr["id"]= "";
 $arr["text"]=$file;
 if(is_dir("C:/QQDownload/".$file)){
  $arr["hasChildren"]= true;
  $arr["id"]= "C:/QQDownload/".$file;
 }
    $province[]=$arr;
   }
}
$abc=json_encode($province);
echo $abc;
closedir($handle); 
}else{
    $id=$_REQUEST ['root'];
    $dir=$id;
 $city = array ();
 $handle=opendir($dir."."); 
while (false !== ($file = readdir($handle)))
{
   if ($file != "." && $file != "..") {
    $arr=array();
    $arr["id"]= "";
 $arr["text"]=$file;
 if(is_dir($dir."/".$file)){
  $arr["hasChildren"]= true;
  $arr["id"]= $dir."/".$file;
 }
    $city[]=$arr;
   }
}
echo json_encode ( $city );
closedir($handle); 
} 
?>
 
                    
                     
                    
                 
                    
                 

 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号