iQu*_*mer 9 javascript jquery jquery-ajaxq
我有一个要求,我需要从客户端的文件夹中检索所有文件名.
因此,我试图使用Jquery检索文件夹中的文件名称,引用此答案.
我的代码如下:
<script>
var fileExt = ".xml";
$(document).ready(
function(){
$.ajax({
//This will retrieve the contents of the folder if the folder is configured as 'browsable'
url: 'xml/',
success: function (data) {
$("#fileNames").html('<ul>');
//List all xml file names in the page
$(data).find('a:contains(" + fileExt + ")').each(function () {
var filename = this.href.replace(window.location, "").replace("http:///", "");
$("#fileNames").append( '<li>'+filename+'</li>');
});
$("#fileNames").append('</ul>');
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
HTML代码如下:
<div id="fileNames"></div>
Run Code Online (Sandbox Code Playgroud)
但是当我在chrome和firefox中运行代码时出现以下错误:
chrome:XMLHttpRequest无法加载file:/// E:/ Test/xml /.收到无效回复.因此不允许原点'null'访问.
Firefox:ReferenceError:$未定义
我试过google很多但错误没有解决.
非常感谢您的帮助.
<html>
<body>
<div id='fileNames'></div>
</body>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$.get(".", function(data)
{
$("#fileNames").append(data);
});
})
</script>
Run Code Online (Sandbox Code Playgroud)
这将打印网页上文件夹中的所有文件。
| 归档时间: |
|
| 查看次数: |
37358 次 |
| 最近记录: |