| 1 |
--- |
| 2 |
title: "Get a file with an ajax call" |
| 3 |
layout: default |
| 4 |
section: example |
| 5 |
--- |
| 6 |
|
| 7 |
<h3>With JSZipUtils</h3> |
| 8 |
|
| 9 |
Note: JSZipUtils is a library available <a href="https://github.com/stuk/jszip-utils">here</a>. |
| 10 |
|
| 11 |
<ul class="nav nav-tabs" role="tablist"> |
| 12 |
<li role="presentation" class="active"> |
| 13 |
<a href="#jszip-utils-result" aria-controls="jszip-utils-result" role="tab" data-toggle="tab"> |
| 14 |
result |
| 15 |
</a> |
| 16 |
</li> |
| 17 |
<li role="presentation"> |
| 18 |
<a href="#jszip-utils-js" aria-controls="jszip-utils-js" role="tab" data-toggle="tab"> |
| 19 |
js code |
| 20 |
</a> |
| 21 |
</li> |
| 22 |
<li role="presentation"> |
| 23 |
<a href="#jszip-utils-html" aria-controls="jszip-utils-html" role="tab" data-toggle="tab"> |
| 24 |
html code |
| 25 |
</a> |
| 26 |
</li> |
| 27 |
</ul> |
| 28 |
<div class="tab-content"> |
| 29 |
<div role="tabpanel" class="tab-pane active" id="jszip-utils-result"> |
| 30 |
<div class="show-example"> |
| 31 |
{% include_relative get-binary-files-ajax.inc/jszip_utils.html %} |
| 32 |
</div> |
| 33 |
</div> |
| 34 |
<div role="tabpanel" class="tab-pane" id="jszip-utils-js"> |
| 35 |
{% highlight js %} |
| 36 |
{% include_relative get-binary-files-ajax.inc/jszip_utils.js %} |
| 37 |
{% endhighlight %} |
| 38 |
</div> |
| 39 |
<div role="tabpanel" class="tab-pane" id="jszip-utils-html"> |
| 40 |
{% highlight html %} |
| 41 |
{% include_relative get-binary-files-ajax.inc/jszip_utils.html %} |
| 42 |
{% endhighlight %} |
| 43 |
</div> |
| 44 |
</div> |
| 45 |
|
| 46 |
<h3>With the Fetch API</h3> |
| 47 |
|
| 48 |
Note: the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"> |
| 49 |
Fetch API</a> is a new javascript API which may not be available everywhere. |
| 50 |
|
| 51 |
<ul class="nav nav-tabs" role="tablist"> |
| 52 |
<li role="presentation" class="active"> |
| 53 |
<a href="#fetch-api-result" aria-controls="fetch-api-result" role="tab" data-toggle="tab"> |
| 54 |
js code |
| 55 |
</a> |
| 56 |
</li> |
| 57 |
<li role="presentation"> |
| 58 |
<a href="#fetch-api-js" aria-controls="fetch-api-js" role="tab" data-toggle="tab"> |
| 59 |
js code |
| 60 |
</a> |
| 61 |
</li> |
| 62 |
<li role="presentation"> |
| 63 |
<a href="#fetch-api-html" aria-controls="fetch-api-html" role="tab" data-toggle="tab"> |
| 64 |
html code |
| 65 |
</a> |
| 66 |
</li> |
| 67 |
</ul> |
| 68 |
<div class="tab-content"> |
| 69 |
<div role="tabpanel" class="tab-pane active" id="fetch-api-result"> |
| 70 |
<div class="show-example"> |
| 71 |
{% include_relative get-binary-files-ajax.inc/fetch_api.html %} |
| 72 |
</div> |
| 73 |
</div> |
| 74 |
<div role="tabpanel" class="tab-pane" id="fetch-api-js"> |
| 75 |
{% highlight js %} |
| 76 |
{% include_relative get-binary-files-ajax.inc/fetch_api.js %} |
| 77 |
{% endhighlight %} |
| 78 |
</div> |
| 79 |
<div role="tabpanel" class="tab-pane" id="fetch-api-html"> |
| 80 |
{% highlight html %} |
| 81 |
{% include_relative get-binary-files-ajax.inc/fetch_api.html %} |
| 82 |
{% endhighlight %} |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
|
| 86 |
<script type="text/javascript"> |
| 87 |
(function () { |
| 88 |
|
| 89 |
//========================= |
| 90 |
// JSZipUtils |
| 91 |
//========================= |
| 92 |
(function () { |
| 93 |
{% include_relative get-binary-files-ajax.inc/jszip_utils.js %} |
| 94 |
})(); |
| 95 |
|
| 96 |
//========================= |
| 97 |
// Fetch API |
| 98 |
//========================= |
| 99 |
(function () { |
| 100 |
var elt = document.getElementById('fetch'); |
| 101 |
if(typeof window.fetch === "function") { |
| 102 |
{% include_relative get-binary-files-ajax.inc/fetch_api.js %} |
| 103 |
} else { |
| 104 |
$("#fetch").append($("<p>", { |
| 105 |
"class": "alert alert-danger", |
| 106 |
text: "This browser doesn't support the Fetch API." |
| 107 |
})); |
| 108 |
} |
| 109 |
})(); |
| 110 |
|
| 111 |
})(); |
| 112 |
</script> |