JavaScript Learning notes-JS get local file information

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.