Here I'm trying to get the list of all file names from a given directory.At this url (http://localhost:3000/dir), I'm having the directory name as "/usr/local".
I'm trying to retrieve all the files from "/usr/local" directory having extension ".txt".
I'm unable to display the file names due to the following error :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/dir. (Reason: CORS header 'Access-Control-Allow-Origin' missing).How can I overcome this issue.Can anyone please help me out ...
My Sample.html :
<html>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<body>
<div id="fileNames"></div>
<script type="text/javascript">
$(window).load(function(){
var fileExt = ".txt";
$(document).ready(function(){
$.ajax({
url: 'http://localhost:3000/dir',
success: function (data) {
console.log(data);
$("#fileNames").html('<ul>');
$(data).find("a:contains(" + fileExt + ")").each(function () {
$("#fileNames").append( '<li>'+$(this).text()+'</li>');
});
$("#fileNames").append('</ul>');
}
});
});
});
</script>
</body>
</html>