Home jquery reading TXT document

reading TXT document





I have such a question: is it possible to read the contents of the .txt file without using PHP and IFRAME so that the contents .txt go to TextArea?

Many say it is impossible, but I know that somehow you can do it. Maybe you, wise men, somehow do?

Answer 1, Authority 100%

If from your domain, or from a user computer, then Ajax or HTML5 / File API.

from a computer:

// Somewhere in the layout there is & lt; input id = "inputfile" type = "file" / & gt;
Inputfile.ONCHANGE = FUNCTION () {
 var file = inputfile.files [0];
 var Reader = New FileReader;
 Reader.ONLoadend = Function (EVT) {
  textarea.value = Reader.Result; // File Content
 Reader.Readastext (File);

C Server

xhr = new xmlhttprequest;
xhr.open ('Get', '/FileS/foo.txt', True);
Xhr.ONReadyStateChange = Function () {
 if (xhr.ReadyState == 4) {
  xhr.onreadystatechange = null;
  if (xhr.status == 200) {
   textarea.value = xhr.responsetext; // File Content
Xhr.send (NULL);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions