K
K
khipster2016-02-26 18:56:30
JavaScript
khipster, 2016-02-26 18:56:30

Is it possible to download file.txt.gz via AJAX and how to unzip it in the browser?

It's just that there are no problems with file.txt:

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <title>AJAX запрос методом GET</title>
  </head>
  <body>
    <h1>AJAX запрос методом GET</h1>
    <textarea id="textarea"></textarea>
    <br>
    <button id="button">Загрузить</button>
    <script>
      document.getElementById("button").onclick = function() {
        var request = new XMLHttpRequest();
        request.open("GET", "file.txt", true);
        request.onreadystatechange = function() {
          if (request.readyState == 4 && request.status == 200) {
            document.getElementById("textarea").value = request.responseText;
          }
        }
        request.send();
      }
    </script>
  </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-02-26
@sim3x

If you have nginx as a proxy, then with a normal setup, it will give txt archived in gz anyway

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question