我是 PHP 新手,我有以下场景;在 PHP 方面,我有一个文件 get_folders.php
<?php
$arr = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/var z/www/scripts')) as $filename)
{
array_push($arr,$filename);
}
print (json_encode($arr));
?>
在 html 方面我有
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function myFunction()
{
$.getJSON("get_folders.php", function(data){
alert("Data Loaded: " + data);
$('#thetable');
var html = '';
for(var i = 0; i < 10 ; i++)
html += '<tr><td>' + data;
$('#thetable').append(html);
});
}
</script>
</head>
<button onclick="myFunction()">Try it</button>
<div>
<table id="thetable">
<th>Header 1</th>
</tr>
<tr>
<td></td>
</tr>
</table>
</div>
.......我可以在php端打印数组,一切都很好。但我唯一得到警报的是
加载的数据:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object对象],[对象对象],[对象对象]