summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/jszip/documentation/examples/get-binary-files-ajax.html
blob: ee7594e4a344db84827a74d578bb59c829e74924 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
title: "Get a file with an ajax call"
layout: default
section: example
---

<p>Tip : check the source of the page !</p>

<h3>With JSZipUtils</h3>
<div id="jszip_utils"></div>

<script type="text/javascript">
(function () {

  function showError(elt, err) {
    elt.innerHTML = "<p class='alert alert-danger'>" + err + "</p>";
  }

  function showContent(elt, type, content) {
    elt.innerHTML = "<p class='alert alert-success'>loaded ! (as a " + type + ")<br/>" +
      "Content = " + content + "</p>";
  }

  //=========================
  // JSZipUtils
  //=========================
  JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) {
    var elt = document.getElementById('jszip_utils');
    if(err) {
      showError(elt, err);
      return;
    }

    try {
      var zip = new JSZip(data);
      showContent(elt, "" + data, zip.file("Hello.txt").asText());
    } catch(e) {
      showError(elt, e);
    }
  });

})();
</script>