Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

792
Visualizações
How do I read txt file from url with javaScript?

I have followed the instruction on this page but I'm unable to solve the problem.

Here's my code: When file link is clicked it downloads the f.txt file. But I want to access the data without downloading through the url.

var file = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=hi&dt=t&dt=t&q=hello';
      function readTextFile(file) {
          var rawFile = new XMLHttpRequest();
          rawFile.open("GET",file,false);
          rawFile.onreadystatechange = function() {
              if(rawFile.readyState === 4) {
                  if(rawFile.status === 200 || rawFile.status === 0)
                  {
                      var allText = rawFile.responseText;
                      alert(allText);
                  }
              }
          }
          rawFile.send(null);
      }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  <body>
      <a id="myLink" href="https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=hi&dt=t&dt=t&q=hello"  ">file link</a>
  </body>

 <script>
     document.querySelector("#myLink").addEventListener("click", function(event){ 
        event.preventDefault(); 
        var file = document.getElementById("myLink").getAttribute("href");
        console.log(file)
        var rawFile = new XMLHttpRequest();
        rawFile.open("GET",file,false);
          rawFile.onreadystatechange = function() {
              if(rawFile.readyState === 4) {
                  if(rawFile.status === 200 || rawFile.status === 0)
                  {
                      var allText = rawFile.responseText;
                      console.log(allText);
                  }
              }
          }
          rawFile.send(null);
    }, false); 

  </script>

This approach will get you the read the content of the file.. This way will be helps to you.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda