When I asked if javascript view files on the server, everyone answered " javascript cannot access the file system of the server because it is client-side scripting language ". But I thought the answer was partially correct, because the browser can display the contents of the server directory if dirlisting is dirlisting . So, I decided to try to parse this conclusion - you do not need to use cgi when you can already see the data that you need in xml format. So here is what I did:
I use lighttpd , and the important elements in lighttpd.conf are:
dir-listing.activate = "enable" #enables directory listing dir-listing.auto-layout = "disable" #simplifies the list style mimetype.assign = ( ".xml" => "text/xml" ) #deals with xmls
test.xml used to test XHR is as follows:
<?xml version="1.0"?> <anchors> <a>foo</a> <a>bar</a> </anchors>
Directory list page created by lighttpd mod_dirlisting.so :
<?xml version="1.0" encoding="iso-8859-1"?> <h2>Index of /directory/</h2> <div class="list"> <table summary="Directory Listing" cellpadding="0" cellspacing="0"> <thead><tr><th class="n">Name</th><th class="m">Last Modified</th><th class="s">Size</th><th class="t">Type</th></tr></thead> <tbody> <tr><td class="n"><a href="../">Parent Directory</a>/</td><td class="m"> </td><td class="s">- </td><td class="t">Directory</td></tr> <tr><td class="n"><a href="foo">foo</a></td><td class="m">2015-Jan-03 13:24:12</td><td class="s">39.4K</td><td class="t">application/octet-stream</td></tr> </tbody> </table> </div>
test.html page used to create XHR :
<html><head></head><body><script> if (window.XMLHttpRequest) var request = new XMLHttpRequest(); else var request = new ActiveXObject('Microsoft.XMLHTTP'); request.open('post', 'test.xml', true); request.send(); if (request) request.onreadystatechange = function() alert(request.responseXML.getElementsByTagName('a')[1].childNodes[0].nodeValue); </script></body></html>
All of which work fine (you get "foo" in the warning window), but when I request.open instead of xml , I get nothing, even in the error console.
source share