JavaScript is run in the browser, so for JavaScript to read local files do not want C + + and Java as easy. There are many ways to read local files on the web, many of them using ActiveXObject controls. ActiveXObject is unique to Microsoft, it can only run in the browser of IE kernel, so it is not a good method.
Here, we introduce a method of reading local files using XML.
The first step:
Ngnix Server Configuration
Download Ngnix (http://nginx.org/en/download.html) and after unpacking, open the nginx\conf\nginx.conf file. Configure the root directory for your HTML script directory. My directory is F:\WEBGL.
Start Ngnix, (direct ngnix/ngnix–s Reload)
1 listen ; 2 server_name localhost; 3 4 #charset koi8-r; 5 6 #access_log logs/host.access.log main; 7 8 Location /{ 9 root F:\webgl; Ten index index.html index.htm; One }
Step Two:
HTML code
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Title</title>6 </Head>7 <Body>8 9 <Script!src="">Ten One functionLoaddoc () { A varxhttp= NewXMLHttpRequest (); - Xhttp.onreadystatechange= function() { - if(Xhttp.readystate== 4 &&Xhttp.status== $) { the for (varxinchxhttp.responsetext) { - Console.log (xhttp.responsetext[x]); - } - } + }; - Xhttp.open ("GET", "Ajax_info.txt", true); + xhttp.send (); A } at - Loaddoc (); - - </Script> - - </Body> in </HTML>
Operation Result:
Text content
Chorme Browser Run Results
JavaScript Learning notes-JS get local file information