title: How to read a text file using JS code?
body: <p>I am trying to read a file while using google charts. It first read he data from a text file and then create chart using that data.
  I wrote this code in JS for this purpose</p>
  
  <pre><code>function readTextFile(file){
      var rawFile = new XMLHttpRequest();
      rawFile.open("GET", file, false); // using synchronous call
      var allText;
      alert("Starting to read text");
      rawFile.onreadystatechange = function ()
      {   
          alert("I am here");
          if(rawFile.readyState === 4)
          {
              if(rawFile.status === 200 || rawFile.status == 0)
              {
                  allText = rawFile.responseText;
              }
          }
      }
      rawFile.send(null);
      alert(allText);
      return allText;
  }
  </code></pre>
  
  <p>The problem is : this method is getting called, but the control is not going in </p>
  
  <pre><code>rawFile.onreadystatechange = function ()
      {    ... }
  </code></pre>
  
  <p>Do anyone have any idea regarding this?
  Thanks in advance!</p>
  
  <p>note: I am sending the file name in the parameter (file). I am not passing the address as both this HTML file and the text file are in the same folder.</p>
  
  <p>update 1: I printed   rawFile.readyState , and it always shows 1 which means server connection established. My code is a simple HTML code, not using any server for this purpose.</p>
  
  <p>update 2: I tried adding file:/// before the file name that is not working too :(</p>