Thursday 31 May 2012

Read text file from JavaScript


Read Text file from JavaScript :

function read() {
      var txtFile = new XMLHttpRequest();
       txtFile.open("GET", "http://localhost:9122/Text.txt", true);
           
       txtFile.onreadystatechange = function () {
        if (txtFile.readyState == 4) {  // Makes sure the document is ready to parse.
          if (txtFile.status == 200) {  // Makes sure it's found the file.
             document.getElementById("div").innerHTML = txtFile.responseText;                       
           }
         }
       }
       txtFile.send(null);
  }

HTML :

<
body onload="read();">
    <form id="form1" runat="server">
    <div id="div">
   
    </div>
    </form>
</body>

Why should be a fan as you are a star of tomorrow

No comments:

Post a Comment