It looks like you launched it by double-clicking the html file. Therefore, it will work in a browser with the file protocol. You must run it from the server, for example http://localhost/myhtml.html .
I tried the code on my system, it works with the server.
Plus
you have a syntax error in the line below
$(data).find('a:contains(" + fileExt + ")').each(function () {
replace above with this
$(data).find("a:contains(" + fileExt + ")").each(function () {
I am on an ubuntu system and with the Chrome browser you do not need to replace the location. because it returns the relative path to the location.
UPDATE
Your last code should look like this:
<script type="text/javascript">//<![CDATA[ $(window).load(function(){ 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) { console.log(data); $("#fileNames").html('<ul>'); //List all xml file names in the page //var filename = this.href.replace(window.location, "").replace("http:///", ""); //$("#fileNames").append( '<li>'+filename+'</li>'); $(data).find("a:contains(" + fileExt + ")").each(function () { $("#fileNames").append( '<li>'+$(this).text()+'</li>'); }); $("#fileNames").append('</ul>'); } }); }); }); //]]> </script>
source share