我有一个来自javascriptkit.com的简单的ajax脚本,它将外部页面加载到div中。当我在那里粘贴我的PHP读取目录脚本时它不起作用。这是否可以实现?下面是ajax ......
<head>
<script type="text/javascript" src="ajaxpagefetcher.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="demo" style="border: 1px dashed gray; width: 300px; height: 200px; padding: 3px;
background: none repeat scroll 0% 0% lightyellow;"></div>
<a href="javascript:ajaxpagefetcher.load('demo', 'PHP SCRIPT HERE', false)">Load Content 1</a>
</body>
这是我正在使用的PHP。
<?php
// These files will be ignored
$excludedFiles = array (
'excludeMe.file',
'excludeMeAs.well'
);
// These file extensions will be ignored
$excludedExtensions = array (
'html',
'xslt',
'htm',
'ahk',
'xsl',
'txt',
'xml'
);
// Make sure we ignore . and ..
$excludedFiles = array_merge($excludedFiles,array('.','..'));
// Convert to lower case so we are not case-sensitive
for ($i = 0; isset($excludedFiles[$i]); $i++) $excludedFiles[$i] =
strtolower(ltrim($excludedFiles[$i],'.'));
for ($i = 0; isset($excludedExtensions[$i]); $i++) $excludedExtensions[$i] =
strtolower($excludedExtensions[$i]);
// Loop through directory
$dir = 'dir/dir/';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$extn = explode('.',$file);
$extn = array_pop($extn);
// Only echo links for files that don't match our rules
if (!in_array(strtolower($file),$excludedFiles) &&
!in_array(strtolower($extn),$excludedExtensions)) {
$count++;
print("<a href=\"".$dir.$file."\">".$file."</a><br />\n");
}
}
echo '<br />';
closedir($handle);
}
?>