Update JSON API
[src/app-framework-demo.git] / afm-client / bower_components / jszip / documentation / examples / get-binary-files-ajax.html
1 ---
2 title: "Get a file with an ajax call"
3 layout: default
4 section: example
5 ---
6
7 <p>Tip : check the source of the page !</p>
8
9 <h3>With JSZipUtils</h3>
10 <div id="jszip_utils"></div>
11
12 <script type="text/javascript">
13 (function () {
14
15   function showError(elt, err) {
16     elt.innerHTML = "<p class='alert alert-danger'>" + err + "</p>";
17   }
18
19   function showContent(elt, type, content) {
20     elt.innerHTML = "<p class='alert alert-success'>loaded ! (as a " + type + ")<br/>" +
21       "Content = " + content + "</p>";
22   }
23
24   //=========================
25   // JSZipUtils
26   //=========================
27   JSZipUtils.getBinaryContent('{{site.baseurl}}/test/ref/text.zip', function(err, data) {
28     var elt = document.getElementById('jszip_utils');
29     if(err) {
30       showError(elt, err);
31       return;
32     }
33
34     try {
35       var zip = new JSZip(data);
36       showContent(elt, "" + data, zip.file("Hello.txt").asText());
37     } catch(e) {
38       showError(elt, e);
39     }
40   });
41
42 })();
43 </script>