title: Javascript, how to read local file?
body: <p>I try to read a local file from server. I have been "googling" this topic for a while now, and some say it's impossible, others that it can be done. During this search I've found this script: </p>
  
  <blockquote>
    <p>Read a file  using xmlhttprequest </p>
    
    <p>If the HTML file with your javascript app has been saved to disk, 
    this is an easy way to read in a data file.  Writing out is 
    more complicated and requires either an ActiveX object (IE) 
    or XPCOM (Mozilla).</p>
    
    <p>fname - relative path to the file</p>
    
    <p>callback - function to call with file text</p>
  </blockquote>
  
  <pre><code>function readFileHttp(fname, callback) {
  
      xmlhttp = getXmlHttp();
  
      xmlhttp.onreadystatechange = function() {
  
          if (xmlhttp.readyState==4) { 
  
              callback(xmlhttp.responseText); 
  
          }
  
      }
  
      xmlhttp.open("GET", fname, true);
  
      xmlhttp.send(null);
  
  }
  </code></pre>
  
  <blockquote>
    <p>Return a cross-browser xmlhttp request object</p>
  </blockquote>
  
  <pre><code>function getXmlHttp() {
  
      if (window.XMLHttpRequest) {
  
          xmlhttp=new XMLHttpRequest();
  
      } else if (window.ActiveXObject) {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  
      }
  
      if (xmlhttp == null) {
  
          alert("Your browser does not support XMLHTTP.");
  
      }
  
      return xmlhttp;
  
  }
  </code></pre>
  
  <p>But I don't know how to use it, and how should callback function look? Could you provide an example code using these functions?</p>